Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-23 08:28:38

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 B02RunAction.cc
0027 /// \brief Implementation of the B02RunAction class
0028 
0029 #include "B02RunAction.hh"
0030 
0031 #include "B02Run.hh"
0032 
0033 //-- In order to obtain detector information.
0034 #include "B02DetectorConstruction.hh"
0035 #include "B02ImportanceDetectorConstruction.hh"
0036 
0037 #include "G4RunManager.hh"
0038 #include "G4THitsMap.hh"
0039 #include "G4UnitsTable.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0042 //
0043 // B02RunAction
0044 //
0045 //
0046 //
0047 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0048 
0049 // Constructor
0050 B02RunAction::B02RunAction()
0051   : G4UserRunAction(),
0052     //  fFieldName(15),
0053     fFieldValue(14)
0054 {
0055   // - Prepare data member for B02Run.
0056   //   vector represents a list of MultiFunctionalDetector names.
0057   fSDName.push_back(G4String("ConcreteSD"));
0058 }
0059 
0060 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0061 
0062 // Destructor.
0063 B02RunAction::~B02RunAction()
0064 {
0065   fSDName.clear();
0066 }
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0069 
0070 G4Run* B02RunAction::GenerateRun()
0071 {
0072   // Generate new RUN object, which is specially
0073   // dedicated for MultiFunctionalDetector scheme.
0074   //  Detail description can be found in B02Run.hh/cc.
0075   return new B02Run(fSDName);
0076 }
0077 
0078 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0079 
0080 void B02RunAction::BeginOfRunAction(const G4Run* aRun)
0081 {
0082   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
0083 }
0084 
0085 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0086 
0087 void B02RunAction::EndOfRunAction(const G4Run* aRun)
0088 {
0089   G4cout << " ###### EndOfRunAction  " << G4endl;
0090   //- B02Run object.
0091   B02Run* b02Run = (B02Run*)aRun;
0092   //--- Dump all socred quantities involved in B02Run.
0093   // re02Run->DumpAllScorer();
0094   //---
0095   G4RunManager* mgr = G4RunManager::GetRunManager();
0096   //
0097 
0098   for (G4int i = 0; i < (G4int)fSDName.size(); i++) {
0099     const G4VUserDetectorConstruction* vdet = mgr->GetUserDetectorConstruction();
0100     B02ImportanceDetectorConstruction* bdet = (B02ImportanceDetectorConstruction*)vdet;
0101     //
0102 
0103     //---------------------------------------------
0104     // Dump accumulated quantities for this RUN.
0105     //  (Display only central region of x-y plane)
0106     //      0       ConcreteSD/Collisions
0107     //      1       ConcreteSD/CollWeight
0108     //      2       ConcreteSD/Population
0109     //      3       ConcreteSD/TrackEnter
0110     //      4       ConcreteSD/SL
0111     //      5       ConcreteSD/SLW
0112     //      6       ConcreteSD/SLWE
0113     //      7       ConcreteSD/SLW_V
0114     //      8       ConcreteSD/SLWE_V
0115     //---------------------------------------------
0116     G4THitsMap<G4double>* Collisions = b02Run->GetHitsMap(fSDName[i] + "/Collisions");
0117     G4THitsMap<G4double>* CollWeight = b02Run->GetHitsMap(fSDName[i] + "/CollWeight");
0118     G4THitsMap<G4double>* Population = b02Run->GetHitsMap(fSDName[i] + "/Population");
0119     G4THitsMap<G4double>* TrackEnter = b02Run->GetHitsMap(fSDName[i] + "/TrackEnter");
0120     G4THitsMap<G4double>* SL = b02Run->GetHitsMap(fSDName[i] + "/SL");
0121     G4THitsMap<G4double>* SLW = b02Run->GetHitsMap(fSDName[i] + "/SLW");
0122     G4THitsMap<G4double>* SLWE = b02Run->GetHitsMap(fSDName[i] + "/SLWE");
0123     G4THitsMap<G4double>* SLW_V = b02Run->GetHitsMap(fSDName[i] + "/SLW_V");
0124     G4THitsMap<G4double>* SLWE_V = b02Run->GetHitsMap(fSDName[i] + "/SLWE_V");
0125 
0126     if (IsMaster()) {
0127       G4cout << "\n--------------------End of Global Run-----------------------" << G4endl;
0128       G4cout << " Number of event processed : " << aRun->GetNumberOfEvent() << G4endl;
0129     }
0130     else {
0131       G4cout << "\n--------------------End of Local Run------------------------" << G4endl;
0132       G4cout << " Number of event processed : " << aRun->GetNumberOfEvent() << G4endl;
0133     }
0134 
0135     G4cout << "=============================================================" << G4endl;
0136     G4cout << "=============================================================" << G4endl;
0137 
0138     std::ostream* myout = &G4cout;
0139     PrintHeader(myout);
0140 
0141     for (G4int iz = 0; iz < 20; iz++) {
0142       G4double* SumCollisions = (*Collisions)[iz];
0143       G4double* SumCollWeight = (*CollWeight)[iz];
0144       G4double* Populations = (*Population)[iz];
0145       G4double* TrackEnters = (*TrackEnter)[iz];
0146       G4double* SLs = (*SL)[iz];
0147       G4double* SLWs = (*SLW)[iz];
0148       G4double* SLWEs = (*SLWE)[iz];
0149       G4double* SLW_Vs = (*SLW_V)[iz];
0150       G4double* SLWE_Vs = (*SLWE_V)[iz];
0151       if (!SumCollisions) SumCollisions = new G4double(0.0);
0152       if (!SumCollWeight) SumCollWeight = new G4double(0.0);
0153       if (!Populations) Populations = new G4double(0.0);
0154       if (!TrackEnters) TrackEnters = new G4double(0.0);
0155       if (!SLs) SLs = new G4double(0.0);
0156       if (!SLWs) SLWs = new G4double(0.0);
0157       if (!SLWEs) SLWEs = new G4double(0.0);
0158       if (!SLW_Vs) SLW_Vs = new G4double(0.0);
0159       if (!SLWE_Vs) SLWE_Vs = new G4double(0.0);
0160       G4double NumWeightedEnergy = 0.0;
0161       G4double FluxWeightedEnergy = 0.0;
0162       G4double AverageTrackWeight = 0.0;
0163       if (*SLW_Vs != 0.) NumWeightedEnergy = (*SLWE_Vs) / (*SLW_Vs);
0164       if (*SLWs != 0.) FluxWeightedEnergy = (*SLWEs) / (*SLWs);
0165       if (*SLs != 0.) AverageTrackWeight = (*SLWs) / (*SLs);
0166       G4String cname = bdet->GetCellName(iz);
0167       G4cout << std::setw(fFieldValue) << cname << " |" << std::setw(fFieldValue) << (*TrackEnters)
0168              << " |" << std::setw(fFieldValue) << (*Populations) << " |" << std::setw(fFieldValue)
0169              << (*SumCollisions) << " |" << std::setw(fFieldValue) << (*SumCollWeight) << " |"
0170              << std::setw(fFieldValue) << NumWeightedEnergy << " |" << std::setw(fFieldValue)
0171              << FluxWeightedEnergy << " |" << std::setw(fFieldValue) << AverageTrackWeight << " |"
0172              << std::setw(fFieldValue) << (*SLs) << " |" << std::setw(fFieldValue) << (*SLWs)
0173              << " |" << std::setw(fFieldValue) << (*SLW_Vs) << " |" << std::setw(fFieldValue)
0174              << (*SLWEs) << " |" << std::setw(fFieldValue) << (*SLWE_Vs) << " |" << G4endl;
0175     }
0176     G4cout << "=============================================" << G4endl;
0177   }
0178 }
0179 
0180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0181 
0182 void B02RunAction::PrintHeader(std::ostream* out)
0183 {
0184   std::vector<G4String> vecScoreName;
0185   vecScoreName.push_back("Tr.Entering");
0186   vecScoreName.push_back("Population");
0187   vecScoreName.push_back("Collisions");
0188   vecScoreName.push_back("Coll*WGT");
0189   vecScoreName.push_back("NumWGTedE");
0190   vecScoreName.push_back("FluxWGTedE");
0191   vecScoreName.push_back("Av.Tr.WGT");
0192   vecScoreName.push_back("SL");
0193   vecScoreName.push_back("SLW");
0194   vecScoreName.push_back("SLW_v");
0195   vecScoreName.push_back("SLWE");
0196   vecScoreName.push_back("SLWE_v");
0197 
0198   // head line
0199   //   std::string vname;
0200   //   vname = FillString("Volume", ' ', fFieldName+1);
0201   //*out << vname << '|';
0202   *out << std::setw(fFieldValue) << "Volume"
0203        << " |";
0204   for (std::vector<G4String>::iterator it = vecScoreName.begin(); it != vecScoreName.end(); it++) {
0205     //      vname = FillString((*it),
0206     //                         ' ',
0207     //                         fFieldValue+1,
0208     //                         false);
0209     //      *out << vname << '|';
0210     *out << std::setw(fFieldValue) << (*it) << " |";
0211   }
0212   *out << G4endl;
0213 }
0214 
0215 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0216 
0217 std::string B02RunAction::FillString(const std::string& name, char c, G4int n, G4bool back)
0218 {
0219   std::string fname("");
0220   G4int k = n - name.size();
0221   if (k > 0) {
0222     if (back) {
0223       fname = name;
0224       fname += std::string(k, c);
0225     }
0226     else {
0227       fname = std::string(k, c);
0228       fname += name;
0229     }
0230   }
0231   else {
0232     fname = name;
0233   }
0234   return fname;
0235 }
0236 
0237 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......