Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-05 08:06:23

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 /// \file RE02RunAction.cc
0027 /// \brief Implementation of the RE02RunAction class
0028 
0029 #include "RE02RunAction.hh"
0030 
0031 #include "RE02Run.hh"
0032 
0033 //-- In order to obtain detector information.
0034 #include "RE02DetectorConstruction.hh"
0035 
0036 #include "G4RunManager.hh"
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4THitsMap.hh"
0039 #include "G4UnitsTable.hh"
0040 
0041 #include <fstream>
0042 //=======================================================================
0043 // RE02RunAction
0044 //
0045 //
0046 //
0047 //=======================================================================
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0050 // Constructor
0051 RE02RunAction::RE02RunAction() : G4UserRunAction(), fNx(0), fNy(0), fNz(0)
0052 {
0053   // - Prepare data member for RE02Run.
0054   //   vector represents a list of MultiFunctionalDetector names.
0055   fSDName.push_back(G4String("PhantomSD"));
0056 }
0057 
0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0059 // Destructor.
0060 RE02RunAction::~RE02RunAction()
0061 {
0062   fSDName.clear();
0063 }
0064 
0065 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0066 //==
0067 G4Run* RE02RunAction::GenerateRun()
0068 {
0069   // Generate new RUN object, which is specially
0070   // dedicated for MultiFunctionalDetector scheme.
0071   //  Detail description can be found in RE02Run.hh/cc.
0072   return new RE02Run(fSDName);
0073 }
0074 
0075 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0076 //==
0077 void RE02RunAction::BeginOfRunAction(const G4Run* aRun)
0078 {
0079   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0080 }
0081 
0082 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0083 //==
0084 void RE02RunAction::EndOfRunAction(const G4Run* aRun)
0085 {
0086   if (!IsMaster()) return;
0087 
0088   //- RE02Run object.
0089   RE02Run* re02Run = (RE02Run*)aRun;
0090   //--- Dump all socred quantities involved in RE02Run.
0091   re02Run->DumpAllScorer();
0092   //---
0093 
0094   //
0095   //- water phantom (Detector) Information.
0096   //-- Number of segments in the water phantom.
0097   const RE02DetectorConstruction* detector =
0098     (const RE02DetectorConstruction*)(G4RunManager::GetRunManager()->GetUserDetectorConstruction());
0099   detector->GetNumberOfSegmentsInPhantom(fNx, fNy, fNz);  // Fill fNx,y,z.
0100 
0101   //---------------------------------------------
0102   // Dump accumulated quantities for this RUN.
0103   //  (Display only central region of x-y plane)
0104   //---------------------------------------------
0105   G4THitsMap<G4double>* totEdep = re02Run->GetHitsMap("PhantomSD/totalEDep");
0106   G4THitsMap<G4double>* proEdep = re02Run->GetHitsMap("PhantomSD/protonEDep");
0107   G4THitsMap<G4double>* proNstep = re02Run->GetHitsMap("PhantomSD/protonNStep");
0108   G4THitsMap<G4double>* passCFx = re02Run->GetHitsMap("PhantomSD/chargedPassCellFlux");
0109   G4THitsMap<G4double>* cFx = re02Run->GetHitsMap("PhantomSD/chargedCellFlux");
0110   G4THitsMap<G4double>* surfFx = re02Run->GetHitsMap("PhantomSD/chargedSurfFlux");
0111   G4THitsMap<G4double>* gCurr00 = re02Run->GetHitsMap("PhantomSD/gammaSurfCurr000");
0112   G4THitsMap<G4double>* gCurr01 = re02Run->GetHitsMap("PhantomSD/gammaSurfCurr001");
0113   G4THitsMap<G4double>* gCurr02 = re02Run->GetHitsMap("PhantomSD/gammaSurfCurr002");
0114   G4THitsMap<G4double>* gCurr03 = re02Run->GetHitsMap("PhantomSD/gammaSurfCurr003");
0115 
0116   G4cout << "=============================================================" << G4endl;
0117   G4cout << " Number of event processed : " << aRun->GetNumberOfEvent() << G4endl;
0118   G4cout << "=============================================================" << G4endl;
0119   G4cout << std::setw(8) << "#Z Cell#";
0120   G4cout << std::setw(16) << totEdep->GetName();
0121   G4cout << std::setw(16) << proEdep->GetName();
0122   G4cout << std::setw(12) << proNstep->GetName();
0123   G4cout << std::setw(21) << passCFx->GetName();
0124   G4cout << std::setw(20) << cFx->GetName();
0125   G4cout << std::setw(20) << surfFx->GetName();
0126   G4cout << std::setw(20) << gCurr00->GetName();
0127   G4cout << std::setw(20) << gCurr01->GetName();
0128   G4cout << std::setw(20) << gCurr02->GetName();
0129   G4cout << std::setw(20) << gCurr03->GetName() << G4endl;
0130   G4int ix = fNx / 2;
0131   G4int iy = fNy / 2;
0132   G4int iz;
0133   // G4double totE, proE, proN,pasCF,CF,surfF,gCr0,gCr1,gCr2,gCr3;
0134   for (iz = 0; iz < fNz; iz++) {
0135     G4double* totED = (*totEdep)[CopyNo(ix, iy, iz)];
0136     G4double* proED = (*proEdep)[CopyNo(ix, iy, iz)];
0137     G4double* proNS = (*proNstep)[CopyNo(ix, iy, iz)];
0138     G4double* pasCF = (*passCFx)[CopyNo(ix, iy, iz)];
0139     G4double* cF = (*cFx)[CopyNo(ix, iy, iz)];
0140     G4double* sfx = (*surfFx)[CopyNo(ix, iy, iz)];
0141     G4double* gcur0 = (*gCurr00)[CopyNo(ix, iy, iz)];
0142     G4double* gcur1 = (*gCurr01)[CopyNo(ix, iy, iz)];
0143     G4double* gcur2 = (*gCurr02)[CopyNo(ix, iy, iz)];
0144     G4double* gcur3 = (*gCurr03)[CopyNo(ix, iy, iz)];
0145     if (!totED) totED = new G4double(0.0);
0146     if (!proED) proED = new G4double(0.0);
0147     if (!proNS) proNS = new G4double(0.0);
0148     if (!pasCF) pasCF = new G4double(0.0);
0149     if (!cF) cF = new G4double(0.0);
0150     if (!sfx) sfx = new G4double(0.0);
0151     if (!gcur0) gcur0 = new G4double(0.0);
0152     if (!gcur1) gcur1 = new G4double(0.0);
0153     if (!gcur2) gcur2 = new G4double(0.0);
0154     if (!gcur3) gcur3 = new G4double(0.0);
0155     G4cout << std::setw(6) << iz << "  " << std::setw(12) << G4BestUnit(*totED, "Energy")
0156            << std::setw(12) << G4BestUnit(*proED, "Energy") << std::setw(12) << (*proNS) << "   "
0157            << std::setw(13) << (*pasCF) * cm * cm << " /cm2" << std::setw(15) << (*cF) * cm * cm
0158            << " /cm2" << std::setw(15) << (*sfx) * cm * cm << " /cm2" << std::setw(15)
0159            << (*gcur0) * cm * cm << " /cm2" << std::setw(15) << (*gcur1) * cm * cm << " /cm2"
0160            << std::setw(15) << (*gcur2) * cm * cm << " /cm2" << std::setw(15) << (*gcur3) * cm * cm
0161            << " /cm2" << G4endl;
0162   }
0163   G4cout << "=============================================" << G4endl;
0164 
0165   std::ofstream file("totED.txt");
0166   for (iz = 0; iz < fNz; iz++) {
0167     for (iy = 0; iy < fNy; iy++) {
0168       for (ix = 0; ix < fNx; ix++) {
0169         G4double* totED = (*totEdep)[CopyNo(ix, iy, iz)];
0170         if (!totED) totED = new G4double(0.0);
0171         file << ix << " " << iy << " " << iz << " " << *totED / MeV << G4endl;
0172       }
0173     }
0174   }
0175   file.close();
0176 }
0177 //
0178 // --