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)
void BookHistoFile (G4String, G4String)
void SaveHistoFile ()
AIDA::IHistogram1D * GetHisto (G4int id)

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
G4String histoFile
AIDA::IAnalysisFactory * m_af
AIDA::ITree * m_tree
AIDA::IHistogram1D * m_histo [2]


Detailed Description

Definition at line 25 of file RunAction.hh.


Constructor & Destructor Documentation

RunAction::RunAction ( DetectorConstruction det  ) 

Definition at line 21 of file RunAction.cc.

00022 :m_detector(det)
00023 {
00024   BookHistoFile( "histograms", "root");
00025 }

RunAction::~RunAction (  ) 

Definition at line 29 of file RunAction.cc.

00030 { 
00031   SaveHistoFile();
00032 }


Member Function Documentation

void RunAction::BeginOfRunAction ( const G4Run *  run  ) 

Definition at line 36 of file RunAction.cc.

00037 {  
00038   G4cout << "### Run " << run->GetRunID() << " start." << G4endl;
00039   
00040   //initialize total energy deposit
00041   //
00042   m_sumEdep = m_sumEdep2 = 0.;
00043   m_nbEntry = 0;
00044   
00045   //construct vector of m_depthDose distribution
00046   //
00047   m_nbSlices = 100;
00048   m_astronautHeight = m_detector->GetAstronautHeight();
00049   m_sliceWidth = m_astronautHeight/m_nbSlices;
00050   m_depthDose.resize(m_nbSlices, 0.);
00051 }

void RunAction::EndOfRunAction ( const G4Run *   ) 

Definition at line 73 of file RunAction.cc.

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

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

Definition at line 35 of file RunAction.hh.

Referenced by EventAction::EndOfEventAction().

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

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

Definition at line 55 of file RunAction.cc.

Referenced by SteppingAction::UserSteppingAction().

00056 {
00057   // check coherence
00058   if (zLocal > m_astronautHeight) {
00059     G4cout << "\n --> warning from RunAction::SumDepthDose() : "
00060            << " zLocal beyond astronaut height : " << zLocal/mm << G4endl;
00061     return;
00062   }
00063   
00064   // compute slice number               
00065   G4int k = int(zLocal/m_sliceWidth);
00066   
00067   // sum edep
00068   m_depthDose[k] += edep; 
00069 }

void RunAction::WriteDepthDose ( G4String  name  ) 

Definition at line 132 of file RunAction.cc.

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

void RunAction::BookHistoFile ( G4String  fileName,
G4String  type 
)

Definition at line 158 of file RunAction.cc.

Referenced by RunAction().

00159 {          
00160   histoFile = fileName + "." + type;
00161   m_af = 0; m_tree = 0;
00162   m_histo[0] = m_histo[1] = 0;
00163   
00164 #ifdef G4ANALYSIS_USE
00165    
00166   // check allowed type
00167   if ((type != "root") && (type != "hbook")) {
00168     G4cout << "\n----> Error in BookHisto. Type = " << type
00169            << " not recognized" <<  G4endl;
00170     return;
00171   }
00172   
00173  // Creating the analysis factory
00174  m_af = AIDA_createAnalysisFactory();
00175  
00176  if (m_af) {
00177    // Creating the m_tree factory
00178    AIDA::ITreeFactory* tf = m_af->createTreeFactory();
00179  
00180    // Creating a m_tree mapped to an hbook file.
00181    G4bool readOnly  = false;
00182    G4bool createNew = true;
00183    G4String options =  "export=root";
00184    m_tree = tf->create(histoFile,type,readOnly,createNew, options);
00185    delete tf;
00186    
00187    if (m_tree) {
00188      // Creating a histogram factory
00189      AIDA::IHistogramFactory* hf = m_af->createHistogramFactory(*m_tree);
00190 
00191      // Creating the histograms
00192      m_histo[0]=hf->createHistogram1D
00193                    ("1","total energy deposit in astronaut",100,0.,500*MeV);
00194                    
00195      m_histo[1]=hf->createHistogram1D
00196                    ("2","edep longitudinal profile",100,0.,50*cm);
00197                    
00198      delete hf;
00199      G4cout << "\n----> Histogram m_tree is opened in " << histoFile << G4endl;
00200    }
00201  }
00202 #endif  
00203 }

void RunAction::SaveHistoFile (  ) 

Definition at line 207 of file RunAction.cc.

Referenced by ~RunAction().

00208 {
00209 #ifdef G4ANALYSIS_USE
00210   m_tree->commit();       // Writing the histograms to the file
00211   m_tree->close();        // and closing the m_tree (and the file)
00212   G4cout << "\n----> Histogram m_tree is saved in " << histoFile << G4endl;
00213       
00214   delete m_tree;
00215   delete m_af;
00216 #endif
00217 }

AIDA::IHistogram1D* RunAction::GetHisto ( G4int  id  )  [inline]

Definition at line 42 of file RunAction.hh.

Referenced by EventAction::EndOfEventAction(), and SteppingAction::UserSteppingAction().

00042 {return m_histo[id];}


Member Data Documentation

Definition at line 45 of file RunAction.hh.

Referenced by BeginOfRunAction(), and EndOfRunAction().

G4double RunAction::m_sumEdep [private]

Definition at line 47 of file RunAction.hh.

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

G4double RunAction::m_sumEdep2 [private]

Definition at line 47 of file RunAction.hh.

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

G4int RunAction::m_nbEntry [private]

Definition at line 48 of file RunAction.hh.

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

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

Definition at line 50 of file RunAction.hh.

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

G4double RunAction::m_astronautHeight [private]

Definition at line 51 of file RunAction.hh.

Referenced by BeginOfRunAction(), and SumDepthDose().

G4double RunAction::m_sliceWidth [private]

Definition at line 52 of file RunAction.hh.

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

G4int RunAction::m_nbSlices [private]

Definition at line 53 of file RunAction.hh.

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

G4String RunAction::histoFile [private]

Definition at line 55 of file RunAction.hh.

Referenced by BookHistoFile(), and SaveHistoFile().

AIDA::IAnalysisFactory* RunAction::m_af [private]

Definition at line 56 of file RunAction.hh.

Referenced by BookHistoFile(), and SaveHistoFile().

AIDA::ITree* RunAction::m_tree [private]

Definition at line 57 of file RunAction.hh.

Referenced by BookHistoFile(), and SaveHistoFile().

AIDA::IHistogram1D* RunAction::m_histo[2] [private]

Definition at line 58 of file RunAction.hh.

Referenced by BookHistoFile(), and GetHisto().


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

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