Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:43

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