Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:16:36

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 // (copied from B1RunAction)
0028 
0029 #include "FARunAction.hh"
0030 #include "FAPrimaryGeneratorAction.hh"
0031 #include "FADetectorConstruction.hh"
0032 
0033 #include "G4RunManager.hh"
0034 #include "G4Run.hh"
0035 #include "G4AccumulableManager.hh"
0036 #include "G4LogicalVolumeStore.hh"
0037 #include "G4LogicalVolume.hh"
0038 #include "G4UnitsTable.hh"
0039 #include "G4SystemOfUnits.hh"
0040 
0041 RunAction::RunAction()
0042 : G4UserRunAction(),
0043   fEdep(0.),
0044   fEdep2(0.)
0045 { 
0046   // add new units for dose
0047   // 
0048   const G4double milligray = 1.e-3*gray;
0049   const G4double microgray = 1.e-6*gray;
0050   const G4double nanogray  = 1.e-9*gray;  
0051   const G4double picogray  = 1.e-12*gray;
0052    
0053   new G4UnitDefinition("milligray", "milliGy" , "Dose", milligray);
0054   new G4UnitDefinition("microgray", "microGy" , "Dose", microgray);
0055   new G4UnitDefinition("nanogray" , "nanoGy"  , "Dose", nanogray);
0056   new G4UnitDefinition("picogray" , "picoGy"  , "Dose", picogray); 
0057 
0058   // Register accumulable to the accumulable manager
0059   G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0060   accumulableManager->RegisterAccumulable(fEdep);
0061   accumulableManager->RegisterAccumulable(fEdep2); 
0062 }
0063 
0064 void RunAction::BeginOfRunAction(const G4Run*)
0065 { 
0066  // inform the runManager to save random number seed
0067  G4RunManager::GetRunManager()->SetRandomNumberStore(false);
0068 
0069  // reset accumulables to their initial values
0070  G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0071  accumulableManager->Reset();
0072 }
0073 
0074 void RunAction::EndOfRunAction(const G4Run* run)
0075 {
0076   G4int nofEvents = run->GetNumberOfEvent();
0077   if (nofEvents == 0) return;
0078 
0079   // Merge accumulables 
0080   G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
0081   accumulableManager->Merge();
0082 
0083   // Compute dose = total energy deposit in a run and its variance
0084   //
0085   G4double edep  = fEdep.GetValue();
0086   G4double edep2 = fEdep2.GetValue();
0087   
0088   G4double rms = edep2 - edep*edep/nofEvents;
0089   if (rms > 0.) rms = std::sqrt(rms); else rms = 0.;  
0090 
0091   const auto* detectorConstruction
0092    = static_cast<const DetectorConstruction*>
0093      (G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0094   G4double mass = detectorConstruction->GetScoringVolume()->GetMass();
0095   G4double dose = edep/mass;
0096   G4double rmsDose = rms/mass;
0097 
0098   // Run conditions
0099   //  note: There is no primary generator action object for "master"
0100   //        run manager for multi-threaded mode.
0101   const auto* generatorAction
0102    = static_cast<const PrimaryGeneratorAction*>
0103      (G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction());
0104   G4String runCondition;
0105   if (generatorAction)
0106   {
0107     const G4ParticleGun* particleGun = generatorAction->GetParticleGun();
0108     runCondition += particleGun->GetParticleDefinition()->GetParticleName();
0109     runCondition += " of ";
0110     G4double particleEnergy = particleGun->GetParticleEnergy();
0111     runCondition += G4BestUnit(particleEnergy,"Energy");
0112   }
0113         
0114   // Print
0115   //  
0116   if (IsMaster()) {
0117     G4cout
0118      << G4endl
0119      << "--------------------End of Global Run-----------------------";
0120   }
0121   else {
0122     G4cout
0123      << G4endl
0124      << "--------------------End of Local Run------------------------";
0125   }
0126   
0127   G4cout
0128      << G4endl
0129      << " The run consists of " << nofEvents << " "<< runCondition
0130      << G4endl
0131      << " Cumulated dose per run, in scoring volume : " 
0132      << G4BestUnit(dose,"Dose") << " rms = " << G4BestUnit(rmsDose,"Dose")
0133      << G4endl
0134      << "------------------------------------------------------------"
0135      << G4endl
0136      << G4endl;
0137 }
0138 
0139 void RunAction::AddEdep(G4double edep)
0140 {
0141   fEdep  += edep;
0142   fEdep2 += edep*edep;
0143 }
0144