Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4PhysChemIO.cc
이 파일의 문서화 페이지로 가기
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::AddEmptyLineInOuputFile()
90 {
91  if(fFileInitialized) fOfstream << G4endl;
92 }
93 
94 //------------------------------------------------------------------------------
95 
96 void FormattedText::CloseFile()
97 {
98  if (fFileInitialized == false) 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,
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 != 0)
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 
172 {
173  fpAnalysisManager = 0;
174 }
175 
176 //------------------------------------------------------------------------------
177 
179 {
180  if (fFileInitialized) return;
181 
182  fNtupleID = fpAnalysisManager->CreateNtuple("PhysChem","PhysChem");
185 
186  //----------------------------------------------------------------------------
187  // valid for H2O only
188  fpAnalysisManager->CreateNtupleIColumn(fNtupleID, "ElectronicModif");
189  // ionization = 0 / excitation = 1 / diss att = 2
191  // valid for ion and exc only
193  // valid for ion and exc only
194 
195  //----------------------------------------------------------------------------
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 
219 {
220 // fpAnalysisManager->Write();
221 // fpAnalysisManager->CloseFile();
222 }
223 
224 //------------------------------------------------------------------------------
225 
227  G4int electronicLevel,
229  const G4Track* theIncomingTrack)
230 {
232 
233  // parent ID
235  theIncomingTrack->GetTrackID());
236 
237  // molecule type
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);
248 
249  //----------------------------------------------------------------------------
250  const G4ThreeVector& parentPos = theIncomingTrack->GetPosition();
251 
255 
260 }
261 
262 //------------------------------------------------------------------------------
263 
264 void G4Analysis::CreateSolvatedElectron(const G4Track* electronTrack,
265  G4ThreeVector* finalPosition)
266 {
268 
269  // parent ID
271  electronTrack->GetTrackID());
272 
273  // molecule type
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
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 != 0)
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 
307 }
308 }
G4double GetKineticEnergy() const
virtual void CreateWaterMolecule(G4int electronicModif, G4int, G4double energy, const G4Track *)
G4VAnalysisManager * fpAnalysisManager
virtual void CloseFile()
#define G4endl
Definition: G4ios.hh:61
G4int GetTrackID() const
G4bool OpenFile(const G4String &fileName="")
double z() const
G4bool FillNtupleIColumn(G4int id, G4int value)
G4int CreateNtupleIColumn(const G4String &name)
G4bool FillNtupleDColumn(G4int id, G4double value)
double G4double
Definition: G4Types.hh:76
virtual void InitializeFile()
G4bool FillNtupleSColumn(G4int id, const G4String &value)
const char * data() const
double energy
Definition: plottest35.C:25
virtual void WriteInto(const G4String &, std::ios_base::openmode mode=std::ios_base::out)
const G4ThreeVector & GetPosition() const
static constexpr double eV
Definition: G4SIunits.hh:215
G4int CreateNtupleDColumn(const G4String &name)
G4int CreateNtupleSColumn(const G4String &name)
int G4int
Definition: G4Types.hh:78
double x() const
G4int CreateNtuple(const G4String &name, const G4String &title)
double y() const
virtual void CreateSolvatedElectron(const G4Track *, G4ThreeVector *finalPosition=0)
static constexpr double nanometer
Definition: G4SIunits.hh:101