Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /* 26 /* 27 * G4PhysChemIO.cc 27 * G4PhysChemIO.cc 28 * 28 * 29 * Created on: 3 févr. 2017 29 * Created on: 3 févr. 2017 30 * Author: matkara 30 * Author: matkara 31 */ 31 */ 32 32 33 #include "G4PhysChemIO.hh" 33 #include "G4PhysChemIO.hh" 34 #include "G4SystemOfUnits.hh" 34 #include "G4SystemOfUnits.hh" 35 #include "G4Track.hh" 35 #include "G4Track.hh" 36 #include "G4VAnalysisManager.hh" 36 #include "G4VAnalysisManager.hh" 37 37 38 using namespace std; 38 using namespace std; 39 39 40 //-------------------------------------------- 40 //------------------------------------------------------------------------------ 41 41 42 namespace G4PhysChemIO{ 42 namespace G4PhysChemIO{ 43 43 44 FormattedText::FormattedText(){ 44 FormattedText::FormattedText(){ 45 fRunID = -1; 45 fRunID = -1; 46 fEventID = -1; 46 fEventID = -1; 47 fFileInitialized = false; 47 fFileInitialized = false; 48 } 48 } 49 49 50 //-------------------------------------------- 50 //------------------------------------------------------------------------------ 51 51 52 FormattedText::~FormattedText(){ 52 FormattedText::~FormattedText(){ 53 CloseFile(); 53 CloseFile(); 54 } 54 } 55 55 56 //-------------------------------------------- 56 //------------------------------------------------------------------------------ 57 57 58 void FormattedText::InitializeFile() 58 void FormattedText::InitializeFile() 59 { 59 { 60 if(fFileInitialized) return; 60 if(fFileInitialized) return; 61 61 62 fOfstream << std::setprecision(6) << std::sc 62 fOfstream << std::setprecision(6) << std::scientific; 63 fOfstream << setw(11) << left << "#Parent ID 63 fOfstream << setw(11) << left << "#Parent ID" << setw(10) << "Molecule" 64 << setw(14) << "Elec Modif" << setw(13) << " 64 << setw(14) << "Elec Modif" << setw(13) << "Energy (eV)" 65 << setw(22) << "X pos of parent [nm]" << set 65 << setw(22) << "X pos of parent [nm]" << setw(22) 66 << "Y pos of parent [nm]" << setw(22) << "Z 66 << "Y pos of parent [nm]" << setw(22) << "Z pos of parent [nm]" 67 << setw(14) << "X pos [nm]" << setw(14) << " 67 << setw(14) << "X pos [nm]" << setw(14) << "Y pos [nm]" 68 << setw(14) << "Z pos [nm]" << G4endl<< setw 68 << setw(14) << "Z pos [nm]" << G4endl<< setw(21) << "#" 69 << setw(13) << "1)io/ex=0/1" 69 << setw(13) << "1)io/ex=0/1" 70 << G4endl 70 << G4endl 71 << setw(21) << "#" 71 << setw(21) << "#" 72 << setw(13) << "2)level=0...5" 72 << setw(13) << "2)level=0...5" 73 << G4endl; 73 << G4endl; 74 74 75 fFileInitialized = true; 75 fFileInitialized = true; 76 } 76 } 77 77 78 //-------------------------------------------- 78 //------------------------------------------------------------------------------ 79 79 80 void FormattedText::WriteInto(const G4String& 80 void FormattedText::WriteInto(const G4String& output, 81 ios_base::openmo 81 ios_base::openmode mode) 82 { 82 { 83 fOfstream.open(output.data(), mode); 83 fOfstream.open(output.data(), mode); 84 fFileInitialized = false; 84 fFileInitialized = false; 85 } 85 } 86 86 87 //-------------------------------------------- 87 //------------------------------------------------------------------------------ 88 88 89 void FormattedText::AddEmptyLineInOutputFile() 89 void FormattedText::AddEmptyLineInOutputFile() 90 { 90 { 91 if(fFileInitialized) fOfstream << G4endl; 91 if(fFileInitialized) fOfstream << G4endl; 92 } 92 } 93 93 94 //-------------------------------------------- 94 //------------------------------------------------------------------------------ 95 95 96 void FormattedText::CloseFile() 96 void FormattedText::CloseFile() 97 { 97 { 98 if (!fFileInitialized) return; << 98 if (fFileInitialized == false) return; 99 99 100 if (fOfstream.is_open()) 100 if (fOfstream.is_open()) 101 { 101 { 102 fOfstream.close(); 102 fOfstream.close(); 103 } 103 } 104 } 104 } 105 105 106 //-------------------------------------------- 106 //------------------------------------------------------------------------------ 107 107 108 void FormattedText::CreateWaterMolecule(G4int 108 void FormattedText::CreateWaterMolecule(G4int modification, 109 G4int 109 G4int electronicLevel, 110 G4doub 110 G4double energy, 111 const 111 const G4Track* theIncomingTrack) 112 { 112 { 113 if(!fFileInitialized) InitializeFile(); 113 if(!fFileInitialized) InitializeFile(); 114 114 115 fOfstream << setw(11) << left << theIncoming 115 fOfstream << setw(11) << left << theIncomingTrack->GetTrackID() 116 << setw(10) << "H2O" << left << modification 116 << setw(10) << "H2O" << left << modification << internal 117 << ":" << right << electronicLevel << left < 117 << ":" << right << electronicLevel << left << setw(11) << "" 118 << std::setprecision(2) << std::fixed << set 118 << std::setprecision(2) << std::fixed << setw(13) 119 << energy / eV << std::setprecision(6) << st 119 << energy / eV << std::setprecision(6) << std::scientific 120 << setw(22) 120 << setw(22) 121 << (theIncomingTrack->GetPosition().x()) / n 121 << (theIncomingTrack->GetPosition().x()) / nanometer 122 << setw(22) 122 << setw(22) 123 << (theIncomingTrack->GetPosition().y()) / n 123 << (theIncomingTrack->GetPosition().y()) / nanometer 124 << setw(22) 124 << setw(22) 125 << (theIncomingTrack->GetPosition().z()) / n 125 << (theIncomingTrack->GetPosition().z()) / nanometer 126 << G4endl; 126 << G4endl; 127 } 127 } 128 128 129 //-------------------------------------------- 129 //------------------------------------------------------------------------------ 130 130 131 void FormattedText::CreateSolvatedElectron(con 131 void FormattedText::CreateSolvatedElectron(const G4Track* theIncomingTrack, 132 G4T 132 G4ThreeVector* finalPosition) 133 { 133 { 134 if(!fFileInitialized) InitializeFile(); 134 if(!fFileInitialized) InitializeFile(); 135 135 136 fOfstream << setw(11) << theIncomingTrack->G 136 fOfstream << setw(11) << theIncomingTrack->GetTrackID() << setw(10) 137 << "e_aq" << setw(14) << -1 << std::setpreci 137 << "e_aq" << setw(14) << -1 << std::setprecision(2) 138 << std::fixed << setw(13) 138 << std::fixed << setw(13) 139 << theIncomingTrack->GetKineticEnergy() / eV 139 << theIncomingTrack->GetKineticEnergy() / eV 140 << std::setprecision(6) << std::scientific < 140 << std::setprecision(6) << std::scientific << setw(22) 141 << (theIncomingTrack->GetPosition().x()) / n 141 << (theIncomingTrack->GetPosition().x()) / nanometer 142 << setw(22) 142 << setw(22) 143 << (theIncomingTrack->GetPosition().y()) / n 143 << (theIncomingTrack->GetPosition().y()) / nanometer 144 << setw(22) 144 << setw(22) 145 << (theIncomingTrack->GetPosition().z()) / n 145 << (theIncomingTrack->GetPosition().z()) / nanometer; 146 146 147 if (finalPosition != nullptr) << 147 if (finalPosition != 0) 148 { 148 { 149 fOfstream << setw(14) << (finalPosition->x 149 fOfstream << setw(14) << (finalPosition->x()) / nanometer << setw(14) 150 << (finalPosition->y()) / nanometer << set 150 << (finalPosition->y()) / nanometer << setw(14) 151 << (finalPosition->z()) / nanometer; 151 << (finalPosition->z()) / nanometer; 152 } 152 } 153 153 154 fOfstream << G4endl; 154 fOfstream << G4endl; 155 } 155 } 156 156 157 //-------------------------------------------- 157 //------------------------------------------------------------------------------ 158 // 158 // 159 // Using G4analysis 159 // Using G4analysis 160 // 160 // 161 161 162 G4Analysis::G4Analysis(G4VAnalysisManager* ana 162 G4Analysis::G4Analysis(G4VAnalysisManager* analysisManager): 163 fpAnalysisManager(analysisManager) 163 fpAnalysisManager(analysisManager) 164 { 164 { 165 fFileInitialized = false; 165 fFileInitialized = false; 166 fNtupleID = -1; 166 fNtupleID = -1; 167 } 167 } 168 168 169 //-------------------------------------------- 169 //------------------------------------------------------------------------------ 170 170 171 G4Analysis::~G4Analysis() 171 G4Analysis::~G4Analysis() 172 { 172 { 173 fpAnalysisManager = nullptr; << 173 fpAnalysisManager = 0; 174 } 174 } 175 175 176 //-------------------------------------------- 176 //------------------------------------------------------------------------------ 177 177 178 void G4Analysis::InitializeFile() 178 void G4Analysis::InitializeFile() 179 { 179 { 180 if (fFileInitialized) return; 180 if (fFileInitialized) return; 181 181 182 fNtupleID = fpAnalysisManager->CreateNtuple( 182 fNtupleID = fpAnalysisManager->CreateNtuple("PhysChem","PhysChem"); 183 fpAnalysisManager->CreateNtupleIColumn(fNtup 183 fpAnalysisManager->CreateNtupleIColumn(fNtupleID, "ParentID"); 184 fpAnalysisManager->CreateNtupleSColumn(fNtup 184 fpAnalysisManager->CreateNtupleSColumn(fNtupleID, "Molecule"); 185 185 186 //------------------------------------------ 186 //---------------------------------------------------------------------------- 187 // valid for H2O only 187 // valid for H2O only 188 fpAnalysisManager->CreateNtupleIColumn(fNtup 188 fpAnalysisManager->CreateNtupleIColumn(fNtupleID, "ElectronicModif"); 189 // ionization = 0 / excitation = 1 / diss at 189 // ionization = 0 / excitation = 1 / diss att = 2 190 fpAnalysisManager->CreateNtupleIColumn(fNtup 190 fpAnalysisManager->CreateNtupleIColumn(fNtupleID, "level"); 191 // valid for ion and exc only 191 // valid for ion and exc only 192 fpAnalysisManager->CreateNtupleDColumn(fNtup 192 fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "Energy_eV"); 193 // valid for ion and exc only 193 // valid for ion and exc only 194 194 195 //------------------------------------------ 195 //---------------------------------------------------------------------------- 196 fpAnalysisManager->CreateNtupleDColumn(fNtup 196 fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "x_parent_nm"); 197 fpAnalysisManager->CreateNtupleDColumn(fNtup 197 fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "y_parent_nm"); 198 fpAnalysisManager->CreateNtupleDColumn(fNtup 198 fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "z_parent_nm"); 199 fpAnalysisManager->CreateNtupleDColumn(fNtup 199 fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "x_nm"); 200 fpAnalysisManager->CreateNtupleDColumn(fNtup 200 fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "y_nm"); 201 fpAnalysisManager->CreateNtupleDColumn(fNtup 201 fpAnalysisManager->CreateNtupleDColumn(fNtupleID, "z_nm"); 202 fpAnalysisManager->FinishNtuple(fNtupleID); 202 fpAnalysisManager->FinishNtuple(fNtupleID); 203 203 204 fFileInitialized = true; 204 fFileInitialized = true; 205 } 205 } 206 206 207 //-------------------------------------------- 207 //------------------------------------------------------------------------------ 208 208 209 void G4Analysis::WriteInto(const G4String& out 209 void G4Analysis::WriteInto(const G4String& output, 210 ios_base::openmode) 210 ios_base::openmode) 211 { 211 { 212 fpAnalysisManager->OpenFile(output); 212 fpAnalysisManager->OpenFile(output); 213 fFileInitialized = false; 213 fFileInitialized = false; 214 } 214 } 215 215 216 //-------------------------------------------- 216 //------------------------------------------------------------------------------ 217 217 218 void G4Analysis::CloseFile() 218 void G4Analysis::CloseFile() 219 { 219 { 220 // fpAnalysisManager->Write(); 220 // fpAnalysisManager->Write(); 221 // fpAnalysisManager->CloseFile(); 221 // fpAnalysisManager->CloseFile(); 222 } 222 } 223 223 224 //-------------------------------------------- 224 //------------------------------------------------------------------------------ 225 225 226 void G4Analysis::CreateWaterMolecule(G4int mod 226 void G4Analysis::CreateWaterMolecule(G4int modification, 227 G4int ele 227 G4int electronicLevel, 228 G4double 228 G4double energy, 229 const G4T 229 const G4Track* theIncomingTrack) 230 { 230 { 231 if(!fFileInitialized) InitializeFile(); 231 if(!fFileInitialized) InitializeFile(); 232 232 233 // parent ID 233 // parent ID 234 fpAnalysisManager->FillNtupleIColumn(fNtuple 234 fpAnalysisManager->FillNtupleIColumn(fNtupleID, 0, 235 theInco 235 theIncomingTrack->GetTrackID()); 236 236 237 // molecule type 237 // molecule type 238 fpAnalysisManager->FillNtupleSColumn(fNtuple 238 fpAnalysisManager->FillNtupleSColumn(fNtupleID, 1, "H2O"); 239 239 240 //------------------------------------------ 240 //---------------------------------------------------------------------------- 241 // valid for H2O only 241 // valid for H2O only 242 242 243 // electronic modif 243 // electronic modif 244 fpAnalysisManager->FillNtupleIColumn(fNtuple 244 fpAnalysisManager->FillNtupleIColumn(fNtupleID, 2, modification); 245 // ionization = 0 / excitation = 1 / diss at 245 // ionization = 0 / excitation = 1 / diss att = 2 246 fpAnalysisManager->FillNtupleIColumn(fNtuple 246 fpAnalysisManager->FillNtupleIColumn(fNtupleID, 3, electronicLevel); 247 fpAnalysisManager->FillNtupleDColumn(fNtuple 247 fpAnalysisManager->FillNtupleDColumn(fNtupleID, 4, energy / eV); 248 248 249 //------------------------------------------ 249 //---------------------------------------------------------------------------- 250 const G4ThreeVector& parentPos = theIncoming 250 const G4ThreeVector& parentPos = theIncomingTrack->GetPosition(); 251 251 252 fpAnalysisManager->FillNtupleDColumn(fNtuple 252 fpAnalysisManager->FillNtupleDColumn(fNtupleID,5,(parentPos.x())/nanometer); 253 fpAnalysisManager->FillNtupleDColumn(fNtuple 253 fpAnalysisManager->FillNtupleDColumn(fNtupleID,6,(parentPos.y())/nanometer); 254 fpAnalysisManager->FillNtupleDColumn(fNtuple 254 fpAnalysisManager->FillNtupleDColumn(fNtupleID,7,(parentPos.z())/nanometer); 255 255 256 fpAnalysisManager->FillNtupleDColumn(fNtuple 256 fpAnalysisManager->FillNtupleDColumn(fNtupleID,8,(parentPos.x())/nanometer); 257 fpAnalysisManager->FillNtupleDColumn(fNtuple 257 fpAnalysisManager->FillNtupleDColumn(fNtupleID,9,(parentPos.y())/nanometer); 258 fpAnalysisManager->FillNtupleDColumn(fNtuple 258 fpAnalysisManager->FillNtupleDColumn(fNtupleID,10,(parentPos.z())/nanometer); 259 fpAnalysisManager->AddNtupleRow(fNtupleID); 259 fpAnalysisManager->AddNtupleRow(fNtupleID); 260 } 260 } 261 261 262 //-------------------------------------------- 262 //------------------------------------------------------------------------------ 263 263 264 void G4Analysis::CreateSolvatedElectron(const 264 void G4Analysis::CreateSolvatedElectron(const G4Track* electronTrack, 265 G4Thre 265 G4ThreeVector* finalPosition) 266 { 266 { 267 if(!fFileInitialized) InitializeFile(); 267 if(!fFileInitialized) InitializeFile(); 268 268 269 // parent ID 269 // parent ID 270 fpAnalysisManager->FillNtupleIColumn(fNtuple 270 fpAnalysisManager->FillNtupleIColumn(fNtupleID, 0, 271 electro 271 electronTrack->GetTrackID()); 272 272 273 // molecule type 273 // molecule type 274 fpAnalysisManager->FillNtupleSColumn(fNtuple 274 fpAnalysisManager->FillNtupleSColumn(fNtupleID, 1, "e_aq"); 275 275 276 //------------------------------------------ 276 //---------------------------------------------------------------------------- 277 // valid for H2O only 277 // valid for H2O only 278 278 279 // electronic modif 279 // electronic modif 280 fpAnalysisManager->FillNtupleIColumn(fNtuple 280 fpAnalysisManager->FillNtupleIColumn(fNtupleID, 2, -1); // electronic modif 281 fpAnalysisManager->FillNtupleIColumn(fNtuple 281 fpAnalysisManager->FillNtupleIColumn(fNtupleID, 3, -1); // electronic level 282 fpAnalysisManager->FillNtupleDColumn(fNtuple 282 fpAnalysisManager->FillNtupleDColumn(fNtupleID, 4, 283 electro 283 electronTrack->GetKineticEnergy() / eV); 284 284 285 //------------------------------------------ 285 //---------------------------------------------------------------------------- 286 const G4ThreeVector& parentPos = electronTra 286 const G4ThreeVector& parentPos = electronTrack->GetPosition(); 287 const double i_nm = 1./nanometer; 287 const double i_nm = 1./nanometer; 288 288 289 fpAnalysisManager->FillNtupleDColumn(fNtuple 289 fpAnalysisManager->FillNtupleDColumn(fNtupleID,5, parentPos.x() *i_nm); 290 fpAnalysisManager->FillNtupleDColumn(fNtuple 290 fpAnalysisManager->FillNtupleDColumn(fNtupleID,6, parentPos.y() *i_nm); 291 fpAnalysisManager->FillNtupleDColumn(fNtuple 291 fpAnalysisManager->FillNtupleDColumn(fNtupleID,7, parentPos.z() *i_nm); 292 292 293 if (finalPosition != nullptr) << 293 if (finalPosition != 0) 294 { 294 { 295 fpAnalysisManager->FillNtupleDColumn(fNtup 295 fpAnalysisManager->FillNtupleDColumn(fNtupleID,8, finalPosition->x()*i_nm); 296 fpAnalysisManager->FillNtupleDColumn(fNtup 296 fpAnalysisManager->FillNtupleDColumn(fNtupleID,9, finalPosition->y()*i_nm); 297 fpAnalysisManager->FillNtupleDColumn(fNtup 297 fpAnalysisManager->FillNtupleDColumn(fNtupleID,10, finalPosition->z()*i_nm); 298 } 298 } 299 else 299 else 300 { 300 { 301 fpAnalysisManager->FillNtupleDColumn(fNtup 301 fpAnalysisManager->FillNtupleDColumn(fNtupleID,8, parentPos.x() *i_nm); 302 fpAnalysisManager->FillNtupleDColumn(fNtup 302 fpAnalysisManager->FillNtupleDColumn(fNtupleID,9, parentPos.y() *i_nm); 303 fpAnalysisManager->FillNtupleDColumn(fNtup 303 fpAnalysisManager->FillNtupleDColumn(fNtupleID,10, parentPos.z() *i_nm); 304 } 304 } 305 305 306 fpAnalysisManager->AddNtupleRow(fNtupleID); 306 fpAnalysisManager->AddNtupleRow(fNtupleID); 307 } 307 } 308 } 308 } 309 309