// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // This is the modified version of the example radioactivedecay/rdecay01/src/SteppingVerbose.cc #include "SteppingVerbose.hh" #include "G4SteppingManager.hh" #include "G4ParticleTypes.hh" #include "G4UnitsTable.hh" #include "G4EmSaturation.hh" #include "G4LossTableManager.hh" #include SteppingVerbose::SteppingVerbose() { filename = "bragg.out"; std::vector stopper; } SteppingVerbose::~SteppingVerbose() {} void SteppingVerbose::TrackingStarted() { std::ofstream hitsfile(filename, std::ios::app); if (hitsfile.is_open()) { hitsfile << std::setiosflags(std::ios::fixed) << std::setprecision(4) << std::setiosflags(std::ios::left) << std::setw(6); CopyState(); if(fTrack->GetDefinition()->GetParticleName()== "proton"){ //G4int prec = G4cout.precision(3); if( verboseLevel > 0 ){ /* G4cout << std::setw( 5) << "Step#" << " " << std::setw( 6) << "X (mm)" << " " << std::setw( 6) << "Y (mm)" << " " << std::setw( 6) << "Z (mm)" << " " << std::setw( 9) << "KineE (MeV)" << " " << std::setw( 9) << "dEStep (MeV)" << " " << std::setw(10) << "StepLeng (mm) " << std::setw(10) << "TrakLeng (mm)" << std::setw(10) << "Volume" << " " << std::setw(10) << "Process" << G4endl; G4cout << std::setw( 5) << fTrack->GetCurrentStepNumber() << " " << std::setw( 9) << fTrack->GetPosition().x() << std::setw( 9) << fTrack->GetPosition().y() << std::setw( 9) << fTrack->GetPosition().z() << std::setw( 11) << fTrack->GetKineticEnergy() << std::setw( 15) << fStep->GetTotalEnergyDeposit() << std::setw( 13) << fStep->GetStepLength() << std::setw( 15) << fTrack->GetTrackLength() << " "; */ // get volume of the current step and write out to file if in // water box G4VPhysicalVolume* volume = fStep->GetPreStepPoint()->GetTouchableHandle()->GetVolume(); if (volume->GetName()=="WaterBox" && fTrack->GetDefinition()->GetParticleName()== "proton") { hitsfile << fStep->GetTotalEnergyDeposit() << "\t" << fStep->GetStepLength() << "\t" << fTrack->GetPosition().z() << "\t" << "0.0" << "\t"; } } /* if(fTrack->GetNextVolume()){ G4cout << std::setw(15) << fTrack->GetVolume()->GetName(); } else { G4cout << "OutOfWorld"; } G4cout << " initStep" << G4endl; */ } // G4cout.precision(prec); } hitsfile.close(); } void SteppingVerbose::StepInfo() { CopyState(); // G4int prec = G4cout.precision(3); // Extract and write the numbers for dE/dx as a function of depth // to a file G4EmSaturation* EmSaturation = G4LossTableManager::Instance()->EmSaturation(); G4double visibleEnergy = EmSaturation->VisibleEnergyDepositionAtAStep(fStep); std::ofstream hitsfile(filename, std::ios::app); if (hitsfile.is_open()) { hitsfile << std::setiosflags(std::ios::fixed) << std::setprecision(4) << std::setiosflags(std::ios::left) << std::setw(6); if( verboseLevel >= 1 ){ if( verboseLevel >= 4 ) VerboseTrack(); if( verboseLevel >= 3 ){ /* G4cout << G4endl; G4cout << std::setw( 5) << "#Step#" << " " << std::setw( 6) << "X (mm)" << " " << std::setw( 6) << "Y (mm)" << " " << std::setw( 6) << "Z (mm)" << " " << std::setw( 9) << "KineE (MeV)" << " " << std::setw( 9) << "dEStep (MeV)" << " " << std::setw(10) << "StepLeng (mm) " << std::setw(10) << "TrakLeng (mm)" << std::setw(10) << "Volume" << " " << std::setw(10) << "Process" << G4endl; */ } /* G4cout << std::setw(5) << fTrack->GetCurrentStepNumber() << " " << std::setw(9) << fTrack->GetPosition().x() << std::setw(9) << fTrack->GetPosition().y() << std::setw(9) << fTrack->GetPosition().z() << std::setw(11) << fTrack->GetKineticEnergy() << std::setw(15) << fStep->GetTotalEnergyDeposit() << std::setw(13) << fStep->GetStepLength() << std::setw(15) << fTrack->GetTrackLength() << " "; */ /* // if( fStepStatus != fWorldBoundary){ if( fTrack->GetNextVolume() != 0 ) { G4cout << std::setw(15) << fTrack->GetVolume()->GetName(); } else { G4cout << std::setw(10) << "OutOfWorld"; } if(fStep->GetPostStepPoint()->GetProcessDefinedStep() != 0){ G4cout << " " << std::setw(10) << fStep->GetPostStepPoint()->GetProcessDefinedStep() ->GetProcessName(); } else { G4cout << " UserLimit"; } G4cout << G4endl; */ if( verboseLevel == 2 ){ /* G4int tN2ndariesTot = fN2ndariesAtRestDoIt + fN2ndariesAlongStepDoIt + fN2ndariesPostStepDoIt; if(tN2ndariesTot>0){ G4cout << " :----- List of 2ndaries - " << "#SpawnInStep=" << std::setw(3) << tN2ndariesTot << "(Rest=" << std::setw(2) << fN2ndariesAtRestDoIt << ",Along=" << std::setw(2) << fN2ndariesAlongStepDoIt << ",Post=" << std::setw(2) << fN2ndariesPostStepDoIt << "), " << "#SpawnTotal=" << std::setw(3) << (*fSecondary).size() << " ---------------" << G4endl; for(size_t lp1=(*fSecondary).size()-tN2ndariesTot; lp1<(*fSecondary).size(); lp1++){ G4cout << " : " << std::setw(6) << G4BestUnit((*fSecondary)[lp1]->GetPosition().x(),"Length") << std::setw(6) << G4BestUnit((*fSecondary)[lp1]->GetPosition().y(),"Length") << std::setw(6) << G4BestUnit((*fSecondary)[lp1]->GetPosition().z(),"Length") << std::setw(6) << G4BestUnit((*fSecondary)[lp1]->GetKineticEnergy(),"Energy") << std::setw(10) << (*fSecondary)[lp1]->GetDefinition()->GetParticleName(); G4cout << G4endl; } G4cout << " :-----------------------------" << "----------------------------------" << "-- EndOf2ndaries Info ---------------" << G4endl; } */ } } //G4cout.precision(prec); } hitsfile.close(); }