RunAction Class Reference

#include <RunAction.hh>

Inheritance diagram for RunAction:

Inheritance graph
[legend]
Collaboration diagram for RunAction:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 RunAction (DetectorConstruction *)
 ~RunAction ()
void BeginOfRunAction (const G4Run *)
void EndOfRunAction (const G4Run *)
void SumEvents (G4double e)
void SumDepthDose (G4double, G4double)
void WriteDepthDose (G4String)

Private Attributes

DetectorConstructionm_detector
G4double m_sumEdep
G4double m_sumEdep2
G4int m_nbEntry
std::vector< G4double > m_depthDose
G4double m_astronautHeight
G4double m_sliceWidth
G4int m_nbSlices


Detailed Description

Definition at line 19 of file RunAction.hh.


Constructor & Destructor Documentation

RunAction::RunAction ( DetectorConstruction det  ) 

Definition at line 17 of file RunAction.cc.

00018 :m_detector(det)
00019 { }

RunAction::~RunAction (  ) 

Definition at line 23 of file RunAction.cc.

00024 { }


Member Function Documentation

void RunAction::BeginOfRunAction ( const G4Run *  run  ) 

Definition at line 28 of file RunAction.cc.

00029 {  
00030   G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
00031   
00032   //initialize total energy deposit
00033   //
00034   m_sumEdep = m_sumEdep2 = 0.;
00035   m_nbEntry = 0;
00036   
00037   //construct vector of m_depthDose distribution
00038   //
00039   m_nbSlices = 100;
00040   m_astronautHeight = m_detector->GetAstronautHeight();
00041   m_sliceWidth = m_astronautHeight/m_nbSlices;
00042   m_depthDose.resize(m_nbSlices, 0.);
00043 }

void RunAction::EndOfRunAction ( const G4Run *   ) 

Definition at line 65 of file RunAction.cc.

00066 { 
00067   G4double meanEd = 0., meanEd2 = 0., rmsEd = 0., error_rel_sum = 0.;
00068   if (m_nbEntry) { 
00069     meanEd = m_sumEdep/m_nbEntry; meanEd2 = m_sumEdep2/m_nbEntry;
00070     G4double variance = meanEd2 - meanEd*meanEd;
00071     if (variance > 0.) rmsEd = std::sqrt(variance);
00072     error_rel_sum = rmsEd/(meanEd*std::sqrt(double(m_nbEntry)));
00073   }
00074    
00075   // choose printing format
00076   std::ios::fmtflags mode = G4cout.flags();
00077   G4cout.setf(std::ios::fixed,std::ios::floatfield);
00078   G4int prec = G4cout.precision(3);   
00079   
00080   //print total energy deposit
00081   //
00082   G4cout
00083     << "\n ---> Nb of non-empty events = " << m_nbEntry
00084     << "\n ---> Mean Edep per event    = " << G4BestUnit(meanEd,"Energy")     
00085     << "\n ---> Total Energy deposited = " << G4BestUnit(m_sumEdep,"Energy")
00086     << " +- " << G4BestUnit(m_sumEdep*error_rel_sum,"Energy")
00087     << "  (-> " << 100*error_rel_sum << " %)" 
00088     << G4endl;
00089     
00090   //get mass of astronaut
00091   //
00092   G4double mass = m_detector->GetAstronaut()->GetLogicalVolume()->GetMass();
00093   
00094   //compute dose
00095   //
00096   G4double dose = m_sumEdep/mass;
00097   G4cout.setf(mode,std::ios::floatfield);
00098   G4cout.precision(5);     
00099   G4cout << " ---> Dose = " << G4BestUnit(dose,"Dose") 
00100          << " +- " << G4BestUnit(dose*error_rel_sum,"Dose") << "\n" 
00101          << G4endl;
00102   
00103   // restaure default formats
00104   G4cout.setf(mode,std::ios::floatfield);
00105   G4cout.precision(prec);
00106         
00107   // convert m_depthDose array from energy to dose
00108   //
00109   for (G4int k=0; k<m_nbSlices; k++)  m_depthDose[k] /= mass;
00110   
00111   // write m_depthDose array on a file
00112   //
00113   WriteDepthDose("depthDose");
00114   
00115   // restaure default formats
00116   G4cout.setf(mode,std::ios::floatfield);
00117   G4cout.precision(prec);    
00118 }

void RunAction::SumEvents ( G4double  e  )  [inline]

Definition at line 29 of file RunAction.hh.

Referenced by EventAction::EndOfEventAction().

00029 { m_sumEdep += e; m_sumEdep2 += e*e; m_nbEntry++; };

void RunAction::SumDepthDose ( G4double  zLocal,
G4double  edep 
)

Definition at line 47 of file RunAction.cc.

Referenced by SteppingAction::UserSteppingAction().

00048 {
00049   // check coherence
00050   if (zLocal > m_astronautHeight) {
00051     G4cout << "\n --> warning from RunAction::SumDepthDose() : "
00052            << " zLocal beyond astronaut height : " << zLocal/mm << G4endl;
00053     return;
00054   }
00055   
00056   // compute slice number               
00057   G4int k = int(zLocal/m_sliceWidth);
00058   
00059   // sum edep
00060   m_depthDose[k] += edep; 
00061 }

void RunAction::WriteDepthDose ( G4String  name  ) 

Definition at line 124 of file RunAction.cc.

Referenced by EndOfRunAction().

00125 { 
00126   G4String fileName = name + ".ascii";
00127   std::ofstream File(fileName, std::ios::out);
00128   
00129   std::ios::fmtflags mode = File.flags();  
00130   File.setf( std::ios::scientific, std::ios::floatfield );
00131   G4int prec = File.precision(4);
00132       
00133   File << "  Longitudinal depth dose distribution \n " 
00134        << "\n  zLocal (mm)\t  m_depthDose(gray) \n" << G4endl;
00135            
00136   G4double zLocal;    
00137   for (G4int k=0; k<m_nbSlices; k++) {
00138      zLocal = (k+0.5)*m_sliceWidth;
00139      File << "  "   << zLocal/mm 
00140           << "\t  " << m_depthDose[k]/gray << G4endl;
00141   }
00142   
00143   // restaure default formats
00144   File.setf(mode,std::ios::floatfield);
00145   File.precision(prec);         
00146 }


Member Data Documentation

Definition at line 35 of file RunAction.hh.

Referenced by BeginOfRunAction(), and EndOfRunAction().

G4double RunAction::m_sumEdep [private]

Definition at line 37 of file RunAction.hh.

Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().

G4double RunAction::m_sumEdep2 [private]

Definition at line 37 of file RunAction.hh.

Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().

G4int RunAction::m_nbEntry [private]

Definition at line 38 of file RunAction.hh.

Referenced by BeginOfRunAction(), EndOfRunAction(), and SumEvents().

std::vector<G4double> RunAction::m_depthDose [private]

Definition at line 40 of file RunAction.hh.

Referenced by BeginOfRunAction(), EndOfRunAction(), SumDepthDose(), and WriteDepthDose().

G4double RunAction::m_astronautHeight [private]

Definition at line 41 of file RunAction.hh.

Referenced by BeginOfRunAction(), and SumDepthDose().

G4double RunAction::m_sliceWidth [private]

Definition at line 42 of file RunAction.hh.

Referenced by BeginOfRunAction(), SumDepthDose(), and WriteDepthDose().

G4int RunAction::m_nbSlices [private]

Definition at line 43 of file RunAction.hh.

Referenced by BeginOfRunAction(), EndOfRunAction(), and WriteDepthDose().


The documentation for this class was generated from the following files:

Generated on Fri Nov 21 10:20:37 2008 for jour3d by  doxygen 1.5.7.1