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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 /*
 27  * G4PhysChemIO.cc
 28  *
 29  *  Created on: 3 févr. 2017
 30  *      Author: matkara
 31  */
 32 
 33 #include "G4PhysChemIO.hh"
 34 #include "G4SystemOfUnits.hh"
 35 #include "G4Track.hh"
 36 #include "G4VAnalysisManager.hh"
 37 
 38 using namespace std;
 39 
 40 //------------------------------------------------------------------------------
 41 
 42 namespace G4PhysChemIO{
 43   
 44 FormattedText::FormattedText(){
 45   fRunID = -1;
 46   fEventID = -1;
 47   fFileInitialized = false;
 48 }
 49   
 50 //------------------------------------------------------------------------------
 51   
 52 FormattedText::~FormattedText(){
 53   CloseFile();
 54 }
 55   
 56 //------------------------------------------------------------------------------
 57   
 58 void FormattedText::InitializeFile()
 59 {
 60   if(fFileInitialized) return;
 61   
 62   fOfstream << std::setprecision(6) << std::scientific;
 63   fOfstream << setw(11) << left << "#Parent ID" << setw(10) << "Molecule"
 64   << setw(14) << "Elec Modif" << setw(13) << "Energy (eV)"
 65   << setw(22) << "X pos of parent [nm]" << setw(22)
 66   << "Y pos of parent [nm]" << setw(22) << "Z pos of parent [nm]"
 67   << setw(14) << "X pos [nm]" << setw(14) << "Y pos [nm]"
 68   << setw(14) << "Z pos [nm]" << G4endl<< setw(21) << "#"
 69   << setw(13) << "1)io/ex=0/1"
 70   << G4endl
 71   << setw(21) << "#"
 72   << setw(13) << "2)level=0...5"
 73   << G4endl;
 74   
 75   fFileInitialized = true;
 76 }
 77 
 78 //------------------------------------------------------------------------------
 79 
 80 void FormattedText::WriteInto(const G4String& output,
 81                               ios_base::openmode mode)
 82 {
 83   fOfstream.open(output.data(), mode);
 84   fFileInitialized = false;
 85 }
 86 
 87 //------------------------------------------------------------------------------
 88 
 89 void FormattedText::AddEmptyLineInOutputFile()
 90 {
 91   if(fFileInitialized) fOfstream << G4endl;
 92 }
 93 
 94 //------------------------------------------------------------------------------
 95 
 96 void FormattedText::CloseFile()
 97 {
 98   if (!fFileInitialized) return;
 99   
100   if (fOfstream.is_open())
101   {
102     fOfstream.close();
103   }
104 }
105 
106 //------------------------------------------------------------------------------
107 
108 void FormattedText::CreateWaterMolecule(G4int modification,
109                                         G4int electronicLevel,
110                                         G4double energy,
111                                         const G4Track* theIncomingTrack)
112 {
113   if(!fFileInitialized) InitializeFile();
114   
115   fOfstream << setw(11) << left << theIncomingTrack->GetTrackID()
116   << setw(10) << "H2O" << left << modification << internal
117   << ":" << right << electronicLevel << left << setw(11) << ""
118   << std::setprecision(2) << std::fixed << setw(13)
119   << energy / eV << std::setprecision(6) << std::scientific
120   << setw(22)
121   << (theIncomingTrack->GetPosition().x()) / nanometer
122   << setw(22)
123   << (theIncomingTrack->GetPosition().y()) / nanometer
124   << setw(22)
125   << (theIncomingTrack->GetPosition().z()) / nanometer
126   << G4endl;
127 }
128 
129 //------------------------------------------------------------------------------
130 
131 void FormattedText::CreateSolvatedElectron(const G4Track* theIncomingTrack,
132                                            G4ThreeVector* finalPosition)
133 {
134   if(!fFileInitialized) InitializeFile();
135   
136   fOfstream << setw(11) << theIncomingTrack->GetTrackID() << setw(10)
137   << "e_aq" << setw(14) << -1 << std::setprecision(2)
138   << std::fixed << setw(13)
139   << theIncomingTrack->GetKineticEnergy() / eV
140   << std::setprecision(6) << std::scientific << setw(22)
141   << (theIncomingTrack->GetPosition().x()) / nanometer
142   << setw(22)
143   << (theIncomingTrack->GetPosition().y()) / nanometer
144   << setw(22)
145   << (theIncomingTrack->GetPosition().z()) / nanometer;
146   
147   if (finalPosition != nullptr)
148   {
149     fOfstream << setw(14) << (finalPosition->x()) / nanometer << setw(14)
150     << (finalPosition->y()) / nanometer << setw(14)
151     << (finalPosition->z()) / nanometer;
152   }
153   
154   fOfstream << G4endl;
155 }
156 
157 //------------------------------------------------------------------------------
158 //
159 // Using G4analysis
160 //
161 
162 G4Analysis::G4Analysis(G4VAnalysisManager* analysisManager):
163 fpAnalysisManager(analysisManager)
164 {
165   fFileInitialized = false;
166   fNtupleID = -1;
167 }
168 
169 //------------------------------------------------------------------------------
170 
171 G4Analysis::~G4Analysis()
172 {
173   fpAnalysisManager = nullptr;
174 }
175 
176 //------------------------------------------------------------------------------
177 
178 void G4Analysis::InitializeFile()
179 {
180   if (fFileInitialized) return;
181   
182   fNtupleID = fpAnalysisManager->CreateNtuple("PhysChem","PhysChem");
183   fpAnalysisManager->CreateNtupleIColumn(fNtupleID, "ParentID");
184   fpAnalysisManager->CreateNtupleSColumn(fNtupleID, "Molecule");
185   
186   //----------------------------------------------------------------------------
187   // valid for H2O only
188   fpAnalysisManager->CreateNtupleIColumn(fNtupleID, "ElectronicModif");
189   // ionization = 0 / excitation = 1 / diss att = 2
190   fpAnalysisManager->CreateNtupleIColumn(fNtupleID, "level");
191   // valid for ion and exc only
192   fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "Energy_eV");
193   // valid for ion and exc only
194   
195   //----------------------------------------------------------------------------
196   fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "x_parent_nm");
197   fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "y_parent_nm");
198   fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "z_parent_nm");
199   fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "x_nm");
200   fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "y_nm");
201   fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "z_nm");
202   fpAnalysisManager->FinishNtuple(fNtupleID);
203   
204   fFileInitialized = true;
205 }
206 
207 //------------------------------------------------------------------------------
208 
209 void G4Analysis::WriteInto(const G4String& output,
210                            ios_base::openmode)
211 {
212   fpAnalysisManager->OpenFile(output);
213   fFileInitialized = false;
214 }
215 
216 //------------------------------------------------------------------------------
217 
218 void G4Analysis::CloseFile()
219 {
220 //  fpAnalysisManager->Write();
221 //  fpAnalysisManager->CloseFile();
222 }
223 
224 //------------------------------------------------------------------------------
225 
226 void G4Analysis::CreateWaterMolecule(G4int modification,
227                                      G4int electronicLevel,
228                                      G4double energy,
229                                      const G4Track* theIncomingTrack)
230 {
231   if(!fFileInitialized) InitializeFile();
232   
233   // parent ID
234   fpAnalysisManager->FillNtupleIColumn(fNtupleID, 0,
235                                        theIncomingTrack->GetTrackID());
236   
237   // molecule type
238   fpAnalysisManager->FillNtupleSColumn(fNtupleID, 1, "H2O");
239   
240   //----------------------------------------------------------------------------
241   // valid for H2O only
242   
243   // electronic modif
244   fpAnalysisManager->FillNtupleIColumn(fNtupleID, 2, modification);
245   // ionization = 0 / excitation = 1 / diss att = 2
246   fpAnalysisManager->FillNtupleIColumn(fNtupleID, 3, electronicLevel);
247   fpAnalysisManager->FillNtupleDColumn(fNtupleID, 4, energy / eV);
248   
249   //----------------------------------------------------------------------------
250   const G4ThreeVector& parentPos = theIncomingTrack->GetPosition();
251   
252   fpAnalysisManager->FillNtupleDColumn(fNtupleID,5,(parentPos.x())/nanometer);
253   fpAnalysisManager->FillNtupleDColumn(fNtupleID,6,(parentPos.y())/nanometer);
254   fpAnalysisManager->FillNtupleDColumn(fNtupleID,7,(parentPos.z())/nanometer);
255   
256   fpAnalysisManager->FillNtupleDColumn(fNtupleID,8,(parentPos.x())/nanometer);
257   fpAnalysisManager->FillNtupleDColumn(fNtupleID,9,(parentPos.y())/nanometer);
258   fpAnalysisManager->FillNtupleDColumn(fNtupleID,10,(parentPos.z())/nanometer);
259   fpAnalysisManager->AddNtupleRow(fNtupleID);
260 }
261 
262 //------------------------------------------------------------------------------
263 
264 void G4Analysis::CreateSolvatedElectron(const G4Track* electronTrack,
265                                         G4ThreeVector* finalPosition)
266 {
267   if(!fFileInitialized) InitializeFile();
268   
269   // parent ID
270   fpAnalysisManager->FillNtupleIColumn(fNtupleID, 0,
271                                        electronTrack->GetTrackID());
272   
273   // molecule type
274   fpAnalysisManager->FillNtupleSColumn(fNtupleID, 1, "e_aq");
275   
276   //----------------------------------------------------------------------------
277   // valid for H2O only
278   
279   // electronic modif
280   fpAnalysisManager->FillNtupleIColumn(fNtupleID, 2, -1); // electronic modif
281   fpAnalysisManager->FillNtupleIColumn(fNtupleID, 3, -1); // electronic level
282   fpAnalysisManager->FillNtupleDColumn(fNtupleID, 4,
283                                        electronTrack->GetKineticEnergy() / eV);
284   
285   //----------------------------------------------------------------------------
286   const G4ThreeVector& parentPos = electronTrack->GetPosition();
287   const double i_nm = 1./nanometer;
288   
289   fpAnalysisManager->FillNtupleDColumn(fNtupleID,5, parentPos.x() *i_nm);
290   fpAnalysisManager->FillNtupleDColumn(fNtupleID,6, parentPos.y() *i_nm);
291   fpAnalysisManager->FillNtupleDColumn(fNtupleID,7, parentPos.z() *i_nm);
292   
293   if (finalPosition != nullptr)
294   {
295     fpAnalysisManager->FillNtupleDColumn(fNtupleID,8, finalPosition->x()*i_nm);
296     fpAnalysisManager->FillNtupleDColumn(fNtupleID,9, finalPosition->y()*i_nm);
297     fpAnalysisManager->FillNtupleDColumn(fNtupleID,10, finalPosition->z()*i_nm);
298   }
299   else
300   {
301     fpAnalysisManager->FillNtupleDColumn(fNtupleID,8, parentPos.x() *i_nm);
302     fpAnalysisManager->FillNtupleDColumn(fNtupleID,9, parentPos.y() *i_nm);
303     fpAnalysisManager->FillNtupleDColumn(fNtupleID,10, parentPos.z() *i_nm);
304   }
305   
306   fpAnalysisManager->AddNtupleRow(fNtupleID);
307 }
308 }
309