Precalibrated Ion Beam Identification Detector Simulation 1.0
A pilot study detector simulation, written in C++ with Geant4.
RunAction.cc
Go to the documentation of this file.
00001 #include "RunAction.hh"
00002 
00003 RunAction::RunAction()
00004 {
00005   myMessenger = new RunActionMessenger(this);
00006   particleZ = 6;
00007   particleA = 17;
00008 }
00009 
00010 RunAction::~RunAction()
00011 {
00012   delete myMessenger;
00013 }
00014 
00015 void RunAction::SetNewResultsFileName(G4String filename)
00016 {
00017   resultsFileName = filename;
00018 }
00019 
00020 void RunAction::SetParticleZ(G4int newZ)
00021 {
00022   particleZ=newZ;
00023 }
00024 
00025 void RunAction::SetParticleA(G4int newA)
00026 {
00027   particleA=newA;
00028 }
00029 
00030 void RunAction::WriteResultsToFile(G4int eventID, AllAccumulatedStatistics * myEventStatistics)
00031 {
00032   std::vector<EventHit> eventsToWrite = myEventStatistics->GetEventHits();
00033   for(std::vector<EventHit>::iterator it = eventsToWrite.begin(); it!=eventsToWrite.end(); it++)
00034     {
00035       fprintf(resultsFile, "%d %d %d ", eventID, particleZ, particleA);
00036 
00037       fprintf(resultsFile, "%.15e ",it->time/ns);
00038       if(it->upperFrontScintillatorPanelEnergy/MeV>1E-100)
00039         fprintf(resultsFile, "%.15e ",it->upperFrontScintillatorPanelEnergy/MeV);
00040       else
00041         fprintf(resultsFile, "%d ",0);
00042       
00043       if(it->lowerFrontScintillatorPanelEnergy/MeV>1E-100)
00044         fprintf(resultsFile, "%.15e ",it->lowerFrontScintillatorPanelEnergy/MeV);
00045       else
00046         fprintf(resultsFile, "%d ",0);
00047 
00048       if(it->backScintillatorPanelEnergy/MeV>1E-100)
00049         fprintf(resultsFile, "%.15e ",it->backScintillatorPanelEnergy/MeV);
00050       else
00051         fprintf(resultsFile, "%d ",0);
00052 
00053       if(it->geDetectorEnergy/MeV>1E-100)
00054         fprintf(resultsFile, "%.15e",it->geDetectorEnergy/MeV);
00055       else
00056         fprintf(resultsFile, "%d",0);
00057 
00058       for(std::vector<G4double>::iterator ig = it->scintillatorTubeEnergies.begin(); ig!=it->scintillatorTubeEnergies.end(); ig++)
00059         {
00060           if(*ig/MeV>1E-100)
00061             fprintf(resultsFile, " %.15e",*ig/MeV);
00062           else
00063             fprintf(resultsFile, " %d",0);
00064         }
00065       fprintf(resultsFile, "\n");
00066     }
00067 }
00068 
00069 void RunAction::BeginOfRunAction(const G4Run* aRun)
00070 { 
00071   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
00072   resultsFile = fopen(resultsFileName.c_str(),"w");
00073 
00074   if(usingVerboseFile)
00075     {
00076       verboseFile = fopen(verboseResultsFileName, "w");  
00077     }
00078   
00079   //inform the runManager to save random number seed
00080   G4RunManager::GetRunManager()->SetRandomNumberStore(false);
00081     
00082 }
00083 
00084 void RunAction::EndOfRunAction(const G4Run* aRun)
00085 {
00086   G4cout << "### End of run " << aRun->GetRunID() << "." << G4endl;
00087   fclose(resultsFile);
00088     if(usingVerboseFile)
00089     {
00090       fprintf(verboseFile, "\n");
00091       fclose(verboseFile);
00092     }
00093 }
00094 
00095 
00096 void RunAction::PrintToVerboseFile(G4String messageToPrint)
00097 {
00098   if(usingVerboseFile)
00099     {
00100       fprintf(verboseFile,"%s",messageToPrint.c_str());
00101     }
00102 }
 All Classes Files Functions Variables Defines

Back to the main page of the Precalibrated Ion Beam Identification Detector project

Created by Rikard Lundmark