00001 // 00002 // ******************************************************************** 00003 // * License and Disclaimer * 00004 // * * 00005 // * The Geant4 software is copyright of the Copyright Holders of * 00006 // * the Geant4 Collaboration. It is provided under the terms and * 00007 // * conditions of the Geant4 Software License, included in the file * 00008 // * LICENSE and available at http://cern.ch/geant4/license . These * 00009 // * include a list of copyright holders. * 00010 // * * 00011 // * Neither the authors of this software system, nor their employing * 00012 // * institutes,nor the agencies providing financial support for this * 00013 // * work make any representation or warranty, express or implied, * 00014 // * regarding this software system or assume any liability for its * 00015 // * use. Please see the license in the file LICENSE and URL above * 00016 // * for the full disclaimer and the limitation of liability. * 00017 // * * 00018 // * This code implementation is the result of the scientific and * 00019 // * technical work of the GEANT4 collaboration. * 00020 // * By using, copying, modifying or distributing the software (or * 00021 // * any work based on the software) you agree to acknowledge its * 00022 // * use in resulting scientific publications, and indicate your * 00023 // * acceptance of all terms of the Geant4 Software license. * 00024 // ******************************************************************** 00025 // 00026 // 00027 // $Id: RunAction.cc,v 1.1 2010-10-18 15:56:17 maire Exp $ 00028 // GEANT4 tag $Name: not supported by cvs2svn $ 00029 // 00030 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00032 00033 #include "RunAction.hh" 00034 00035 #include "myglobals.hh" 00036 #include "G4Run.hh" 00037 #include "G4RunManager.hh" 00038 #include "G4UnitsTable.hh" 00039 00040 #include "G4EnergyLossTables.hh" 00041 #include "G4ProductionCutsTable.hh" 00042 #include "G4ParticleDefinition.hh" 00043 #include "G4LossTableManager.hh" 00044 00045 #include "G4EmCalculator.hh" 00046 #include "G4ParticleTable.hh" 00047 #include "G4VPhysicalVolume.hh" 00048 00049 #include "DetectorConstruction.hh" 00050 #include "MyGlobalField.hh" 00051 00052 #include "MyAnalysisSvc.hh" 00053 00054 #include <time.h> 00055 #include <iomanip> 00056 #include <sstream> 00057 #include <fstream> 00058 #include <iostream> 00059 #include <stdlib.h> 00060 00061 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00062 00063 RunAction::RunAction() 00064 { 00065 } 00066 00067 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00068 00069 RunAction::~RunAction() 00070 { 00071 } 00072 00073 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00074 00075 void RunAction::BeginOfRunAction(const G4Run* aRun) 00076 { 00077 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 00078 00079 //inform the runManager to save random number seed 00080 G4RunManager::GetRunManager()->SetRandomNumberStore(true); 00081 00082 //deal with analysis 00083 MyAnalysisSvc::GetMyAnalysisSvc()->BeginOfRunAction(); 00084 00085 //t_begin = (double)clock(); 00086 00087 FieldList* fields = MyGlobalField::getObject()->getFields(); 00088 if (fields) { 00089 if (fields->size()>0) { 00090 FieldList::iterator i; 00091 for (i=fields->begin(); i!=fields->end(); ++i) { 00092 (*i)->construct(); 00093 //G4cout << "Constructed field " << G4endl; 00094 } 00095 } 00096 } 00097 00098 /* 00099 //#################################################################################333 00100 //Print dE/dx tables with binning identical to the Geant3 JMATE bank. 00101 //The printout is readable as Geant3 ffread data cards (by the program g4mat). 00102 // 00103 const G4double tkmin=10*keV, tkmax=20*GeV; 00104 const G4int nbin=100; 00105 G4double tk[nbin]; 00106 00107 const G4int ncolumn = 1; 00108 00109 //compute the kinetic energies 00110 // 00111 const G4double dp = std::log10(tkmax/tkmin)/nbin; 00112 const G4double dt = std::pow(10.,dp); 00113 tk[0] = tkmin; 00114 for (G4int i=1; i<nbin; ++i) tk[i] = tk[i-1]*dt; 00115 00116 //print the kinetic energies 00117 // 00118 std::ios::fmtflags mode = G4cout.flags(); 00119 G4cout.setf(std::ios::fixed,std::ios::floatfield); 00120 G4int prec = G4cout.precision(3); 00121 00122 //print the dE/dx tables 00123 // 00124 G4cout.setf(std::ios::scientific,std::ios::floatfield); 00125 00126 G4ParticleDefinition* 00127 // part = G4ParticleTable::GetParticleTable()->FindParticle("e-"); 00128 part = G4ParticleTable::GetParticleTable()->FindParticle("mu-"); 00129 00130 G4ProductionCutsTable* theCoupleTable = 00131 G4ProductionCutsTable::GetProductionCutsTable(); 00132 size_t numOfCouples = theCoupleTable->GetTableSize(); 00133 const G4MaterialCutsCouple* couple = 0; 00134 00135 for (size_t i=0; i<numOfCouples; i++) { 00136 couple = theCoupleTable->GetMaterialCutsCouple(i); 00137 const G4Material* mat = couple->GetMaterial(); 00138 G4cout << "\nLIST"; 00139 G4cout << "\nC \nC dE/dx (MeV/cm) for " << part->GetParticleName() 00140 << " in " << mat ->GetName() << "\nC"; 00141 G4cout.precision(6); 00142 G4cout << "\nEnergy/MeV dE/dx (MeV/cm)\n "; 00143 for (G4int l=0;l<nbin; ++l) 00144 { 00145 G4cout << tk[l]/MeV<< "\t"; 00146 G4double dedx = G4LossTableManager::Instance() 00147 ->GetDEDX(part,tk[l],couple); 00148 G4cout << dedx/(MeV/cm) << "\n"; 00149 } 00150 G4cout << G4endl; 00151 } 00152 00153 G4cout.precision(prec); 00154 G4cout.setf(mode,std::ios::floatfield); 00155 //#################################################################################333 00156 */ 00157 00158 00159 } 00160 00161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 00162 00163 void RunAction::EndOfRunAction(const G4Run* aRun) 00164 { 00165 00166 //deal with analysis 00167 MyAnalysisSvc::GetMyAnalysisSvc()->EndOfRunAction(aRun); 00168 00169 G4int NbOfEvents = aRun->GetNumberOfEvent(); 00170 if (NbOfEvents == 0) return; 00171 00172 //t_end = clock(); 00173 //double duration = (t_end-t_begin)/CLOCKS_PER_SEC; 00174 //std::cout<<"TOTAL TIME COST FOR THIS RUN: "<<duration<<"s"<<std::endl; 00175 //std::cout<<"TIME COST PER EVENT FOR THIS RUN: "<<duration/NbOfEvents<<"s"<<std::endl; 00176 } 00177 00178 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......