Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 08:29:02

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