Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 /// \file electromagnetic/TestEm4/src/RunActio << 23 // $Id: RunAction.cc,v 1.9 2005/12/06 11:44:55 gcosmo Exp $ 27 /// \brief Implementation of the RunAction cla << 24 // GEANT4 tag $Name: geant4-08-00 $ 28 // << 25 // 29 // << 30 //....oooOO0OOooo........oooOO0OOooo........oo 26 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oo 27 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 28 33 #include "RunAction.hh" 29 #include "RunAction.hh" 34 30 35 #include "PrimaryGeneratorAction.hh" << 36 << 37 #include "G4AnalysisManager.hh" << 38 #include "G4ParticleGun.hh" << 39 #include "G4Run.hh" 31 #include "G4Run.hh" 40 #include "G4RunManager.hh" 32 #include "G4RunManager.hh" 41 #include "G4SystemOfUnits.hh" << 33 42 #include "G4UnitsTable.hh" << 43 #include "Randomize.hh" 34 #include "Randomize.hh" 44 35 >> 36 #ifdef G4ANALYSIS_USE >> 37 #include "AIDA/AIDA.h" >> 38 #endif >> 39 45 //....oooOO0OOooo........oooOO0OOooo........oo 40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 41 47 RunAction::RunAction() 42 RunAction::RunAction() >> 43 :af(0), tree(0) 48 { 44 { 49 G4AnalysisManager* analysisManager = G4Analy << 45 histo[0] = 0; 50 analysisManager->SetDefaultFileType("root"); << 46 51 analysisManager->SetVerboseLevel(1); << 47 #ifdef G4ANALYSIS_USE 52 analysisManager->SetFirstHistoId(1); << 48 // Creating the analysis factory 53 << 49 af = AIDA_createAnalysisFactory(); 54 // Creating histograms << 50 55 // << 51 if (af) { 56 analysisManager->CreateH1("1", "energy (MeV) << 52 // Creating the tree factory >> 53 AIDA::ITreeFactory* tf = af->createTreeFactory(); >> 54 >> 55 // Creating a tree mapped to an hbook file. >> 56 G4bool readOnly = false; >> 57 G4bool createNew = true; >> 58 G4String options = "--noErrors uncompress"; >> 59 tree = tf->create("testem4.hbook","hbook",readOnly,createNew, options); >> 60 //tree = tf->create("testem4.root","root",readOnly,createNew, options); >> 61 //tree = tf->create("testem4.XML" ,"XML" ,readOnly,createNew, options); >> 62 delete tf; >> 63 >> 64 if (tree) { >> 65 // Creating a histogram factory >> 66 AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree); >> 67 >> 68 // Creating the histogram >> 69 histo[0]=hf->createHistogram1D >> 70 ("1","total energy deposit in C6F6(MeV)",100,0.,10.); >> 71 >> 72 delete hf; >> 73 G4cout << "\n----> Histogram tree is opened" << G4endl; >> 74 } >> 75 } >> 76 #endif 57 } 77 } 58 78 59 //....oooOO0OOooo........oooOO0OOooo........oo 79 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 80 61 void RunAction::BeginOfRunAction(const G4Run*) << 81 RunAction::~RunAction() 62 { 82 { 63 // show Rndm status << 83 #ifdef G4ANALYSIS_USE 64 if (isMaster) G4Random::showEngineStatus(); << 84 tree->commit(); // Writing the histograms to the file 65 << 85 tree->close(); // and closing the tree (and the file) 66 // Get analysis manager << 86 67 G4AnalysisManager* analysisManager = G4Analy << 87 delete tree; 68 << 88 delete af; 69 // Open an output file << 89 #endif 70 // << 71 G4String fileName = "testem4"; << 72 analysisManager->OpenFile(fileName); << 73 } 90 } 74 91 75 //....oooOO0OOooo........oooOO0OOooo........oo 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 76 93 77 void RunAction::EndOfRunAction(const G4Run* ru << 94 >> 95 void RunAction::BeginOfRunAction(const G4Run* aRun) 78 { 96 { 79 G4int nofEvents = run->GetNumberOfEvent(); << 97 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 80 if (nofEvents == 0) return; << 81 98 82 G4AnalysisManager* analysisManager = G4Analy << 99 // save Rndm status >> 100 G4RunManager::GetRunManager()->SetRandomNumberStore(true); >> 101 CLHEP::HepRandom::showEngineStatus(); >> 102 } 83 103 84 if (isMaster) { << 104 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 85 // Run conditions << 86 // note: There is no primary generator ac << 87 // run manager for multi-threaded m << 88 PrimaryGeneratorAction* generatorAction = << 89 (PrimaryGeneratorAction*)(G4RunManager:: << 90 G4String runCondition = " "; << 91 if (generatorAction) { << 92 G4ParticleGun* particleGun = generatorAc << 93 runCondition = particleGun->GetParticleD << 94 runCondition += " of "; << 95 G4double particleEnergy = particleGun->G << 96 runCondition += G4BestUnit(particleEnerg << 97 runCondition += " in a volume of C6F6 "; << 98 } << 99 << 100 G4cout << G4endl << "--------------------E << 101 G4cout << G4endl << " The run consists of << 102 if (analysisManager->GetH1(1)) { << 103 G4cout << " Energy deposit per event: m << 104 << G4BestUnit(analysisManager->Ge << 105 << " rms = " << G4BestUnit(ana << 106 << "----------------------------- << 107 } << 108 } << 109 105 >> 106 void RunAction::EndOfRunAction(const G4Run*) >> 107 { 110 // show Rndm status 108 // show Rndm status 111 if (isMaster) G4Random::showEngineStatus(); << 109 CLHEP::HepRandom::showEngineStatus(); 112 << 113 // save histograms << 114 analysisManager->Write(); << 115 analysisManager->CloseFile(); << 116 } 110 } 117 111 118 //....oooOO0OOooo........oooOO0OOooo........oo 112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 119 113