Advertisement
luizrosalba

GEANT4- RunAction.cpp

Nov 17th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. //
  2. // ********************************************************************
  3. // * License and Disclaimer *
  4. // * *
  5. // * The Geant4 software is copyright of the Copyright Holders of *
  6. // * the Geant4 Collaboration. It is provided under the terms and *
  7. // * conditions of the Geant4 Software License, included in the file *
  8. // * LICENSE and available at http://cern.ch/geant4/license . These *
  9. // * include a list of copyright holders. *
  10. // * *
  11. // * Neither the authors of this software system, nor their employing *
  12. // * institutes,nor the agencies providing financial support for this *
  13. // * work make any representation or warranty, express or implied, *
  14. // * regarding this software system or assume any liability for its *
  15. // * use. Please see the license in the file LICENSE and URL above *
  16. // * for the full disclaimer and the limitation of liability. *
  17. // * *
  18. // * This code implementation is the result of the scientific and *
  19. // * technical work of the GEANT4 collaboration. *
  20. // * By using, copying, modifying or distributing the software (or *
  21. // * any work based on the software) you agree to acknowledge its *
  22. // * use in resulting scientific publications, and indicate your *
  23. // * acceptance of all terms of the Geant4 Software license. *
  24. // ********************************************************************
  25. //
  26. /// \file electromagnetic/TestEm5/src/RunAction.cc
  27. /// \brief Implementation of the RunAction class
  28. //
  29. // $Id: RunAction.cc 76464 2013-11-11 10:22:56Z gcosmo $
  30. //
  31. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  32. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  33.  
  34. #include "RunAction.hh"
  35. #include "DetectorConstruction.hh"
  36. #include "PrimaryGeneratorAction.hh"
  37. #include "HistoManager.hh"
  38. #include "Run.hh"
  39.  
  40. #include "G4Run.hh"
  41. #include "G4RunManager.hh"
  42. #include "G4UnitsTable.hh"
  43. #include "G4EmCalculator.hh"
  44.  
  45. #include "Randomize.hh"
  46. #include "G4SystemOfUnits.hh"
  47. #include <iomanip>
  48.  
  49. #include "Randomize.hh"
  50.  
  51. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  52.  
  53. RunAction::RunAction(DetectorConstruction* det, PrimaryGeneratorAction* kin)
  54. :G4UserRunAction(),fDetector(det), fPrimary(kin), fRun(0), fHistoManager(0)
  55. {
  56. // Book predefined histograms
  57. fHistoManager = new HistoManager();
  58. long seeds[2];
  59. double systime = time(NULL);
  60. seeds[0] = (long) systime;
  61. seeds[1] = (long) (systime*G4UniformRand());
  62. G4Random::setTheSeeds(seeds);
  63. }
  64.  
  65. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  66.  
  67. RunAction::~RunAction()
  68. {
  69. delete fHistoManager;
  70. }
  71.  
  72. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  73.  
  74. G4Run* RunAction::GenerateRun()
  75. {
  76. fRun = new Run(fDetector);
  77. return fRun;
  78. }
  79.  
  80. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  81.  
  82. void RunAction::BeginOfRunAction(const G4Run*)
  83. {
  84. // save Rndm status
  85. //// G4RunManager::GetRunManager()->SetRandomNumberStore(true);
  86. G4Random::showEngineStatus();
  87.  
  88. // keep run condition
  89. if ( fPrimary ) {
  90. G4ParticleDefinition* particle
  91. = fPrimary->GetParticleGun()->GetParticleDefinition();
  92. G4double energy = fPrimary->GetParticleGun()->GetParticleEnergy();
  93. fRun->SetPrimary(particle, energy);
  94. }
  95.  
  96. //histograms
  97. //
  98. G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
  99. if ( analysisManager->IsActive() ) {
  100. analysisManager->OpenFile();
  101. }
  102. }
  103.  
  104. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
  105.  
  106. void RunAction::EndOfRunAction(const G4Run* aRun)
  107. {
  108.  
  109. const Run* theRun= static_cast<const Run*> (aRun);
  110.  
  111. // int tamanho_CC = theRun->tamanho;
  112. // G4int energia_maxima_CC = theRun->energia_maxima;
  113. // std::vector<int>energias_disc_CC (theRun->energias_disc);
  114.  
  115.  
  116. if(IsMaster())
  117. {
  118. char *nome_espectro_discreto ;
  119. nome_espectro_discreto = new char[13];
  120. nome_espectro_discreto="en_disc.out";
  121.  
  122.  
  123. G4cout << " Master executando " << G4endl;
  124. /// reunindo todas as informacoes em apenas um vetor
  125. G4cout << " Imprimindo os resultados " << G4endl;
  126.  
  127. if (ImprimeArquivo_disc == 1 )
  128. {
  129. std::ofstream out_energia_disc;
  130. out_energia_disc.open(nome_espectro_discreto, std::ofstream::out);
  131. for (unsigned int i = 0 ; i < theRun->energias_disc.size() ; i++ ) /// descomentar para ver resultados
  132. {
  133. /// testados , os somatorios são realmente feitos
  134. out_energia_disc << theRun->Calibracao(i,0,theRun->energia_maxima,theRun->energias_disc.size()) << " " << theRun->energias_disc.at(i) << G4endl;
  135. }
  136. out_energia_disc.close();
  137. G4cout << " Escrito no arquivo en_disc.out com sucesso " << G4endl;
  138.  
  139. }
  140.  
  141. }
  142. G4int TotNbofEvents = aRun->GetNumberOfEvent();
  143. if (TotNbofEvents == 0) return;
  144.  
  145. // print Run summary
  146. //
  147. fRun->PrintSummary();
  148.  
  149. // normalize histograms
  150. //
  151. G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
  152.  
  153. G4int ih = 1;
  154. G4double binWidth = analysisManager->GetH1Width(ih);
  155. G4double unit = analysisManager->GetH1Unit(ih);
  156. G4double fac = unit/(TotNbofEvents*binWidth);
  157. analysisManager->ScaleH1(ih,fac);
  158.  
  159. ih = 10;
  160. binWidth = analysisManager->GetH1Width(ih);
  161. unit = analysisManager->GetH1Unit(ih);
  162. fac = unit/(TotNbofEvents*binWidth);
  163. analysisManager->ScaleH1(ih,fac);
  164.  
  165. ih = 12;
  166. analysisManager->ScaleH1(ih,1./TotNbofEvents);
  167.  
  168. // save histograms
  169. if ( analysisManager->IsActive() ) {
  170. analysisManager->Write();
  171. analysisManager->CloseFile();
  172. }
  173.  
  174. // show Rndm status
  175. G4Random::showEngineStatus();
  176. }
  177.  
  178. //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement