Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:20:44

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