Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ********************************************************************
- // * 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. *
- // ********************************************************************
- //
- /// \file electromagnetic/TestEm5/src/RunAction.cc
- /// \brief Implementation of the RunAction class
- //
- // $Id: RunAction.cc 76464 2013-11-11 10:22:56Z gcosmo $
- //
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- #include "RunAction.hh"
- #include "DetectorConstruction.hh"
- #include "PrimaryGeneratorAction.hh"
- #include "HistoManager.hh"
- #include "Run.hh"
- #include "G4Run.hh"
- #include "G4RunManager.hh"
- #include "G4UnitsTable.hh"
- #include "G4EmCalculator.hh"
- #include "Randomize.hh"
- #include "G4SystemOfUnits.hh"
- #include <iomanip>
- #include "Randomize.hh"
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin)
- :G4UserRunAction(),fDetector(det), fPrimary(kin), fRun(0), fHistoManager(0)
- {
- // Book predefined histograms
- fHistoManager = new HistoManager();
- long seeds[2];
- double systime = time(NULL);
- seeds[0] = (long) systime;
- seeds[1] = (long) (systime*G4UniformRand());
- G4Random::setTheSeeds(seeds);
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- RunAction::~RunAction()
- {
- delete fHistoManager;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- G4Run* RunAction::GenerateRun()
- {
- fRun = new Run(fDetector);
- return fRun;
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void RunAction::BeginOfRunAction(const G4Run*)
- {
- // save Rndm status
- //// G4RunManager::GetRunManager()->SetRandomNumberStore(true);
- G4Random::showEngineStatus();
- // keep run condition
- if ( fPrimary ) {
- G4ParticleDefinition* particle
- = fPrimary->GetParticleGun()->GetParticleDefinition();
- G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
- fRun->SetPrimary(particle, energy);
- }
- //histograms
- //
- G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
- if ( analysisManager->IsActive() ) {
- analysisManager->OpenFile();
- }
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
- void RunAction::EndOfRunAction(const G4Run* aRun)
- {
- const Run* theRun= static_cast<const Run*> (aRun);
- // int tamanho_CC = theRun->tamanho;
- // G4int energia_maxima_CC = theRun->energia_maxima;
- // std::vector<int>energias_disc_CC (theRun->energias_disc);
- if(IsMaster())
- {
- char *nome_espectro_discreto ;
- nome_espectro_discreto = new char[13];
- nome_espectro_discreto="en_disc.out";
- G4cout << " Master executando " << G4endl;
- /// reunindo todas as informacoes em apenas um vetor
- G4cout << " Imprimindo os resultados " << G4endl;
- if (ImprimeArquivo_disc == 1 )
- {
- std::ofstream out_energia_disc;
- out_energia_disc.open(nome_espectro_discreto, std::ofstream::out);
- for (unsigned int i = 0 ; i < theRun->energias_disc.size() ; i++ ) /// descomentar para ver resultados
- {
- /// testados , os somatorios são realmente feitos
- out_energia_disc << theRun->Calibracao(i,0,theRun->energia_maxima,theRun->energias_disc.size()) << " " << theRun->energias_disc.at(i) << G4endl;
- }
- out_energia_disc.close();
- G4cout << " Escrito no arquivo en_disc.out com sucesso " << G4endl;
- }
- }
- G4int TotNbofEvents = aRun->GetNumberOfEvent();
- if (TotNbofEvents == 0) return;
- // print Run summary
- //
- fRun->PrintSummary();
- // normalize histograms
- //
- G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
- G4int ih = 1;
- G4double binWidth = analysisManager->GetH1Width(ih);
- G4double unit = analysisManager->GetH1Unit(ih);
- G4double fac = unit/(TotNbofEvents*binWidth);
- analysisManager->ScaleH1(ih,fac);
- ih = 10;
- binWidth = analysisManager->GetH1Width(ih);
- unit = analysisManager->GetH1Unit(ih);
- fac = unit/(TotNbofEvents*binWidth);
- analysisManager->ScaleH1(ih,fac);
- ih = 12;
- analysisManager->ScaleH1(ih,1./TotNbofEvents);
- // save histograms
- if ( analysisManager->IsActive() ) {
- analysisManager->Write();
- analysisManager->CloseFile();
- }
- // show Rndm status
- G4Random::showEngineStatus();
- }
- //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement