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5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 /// \file biasing/B03/src/B03RunAction.cc
 27 /// \brief Implementation of the B03RunAction class
 28 //
 29 //
 30 //
 31 #include "B03RunAction.hh"
 32 
 33 #include "B03Run.hh"
 34 
 35 //-- In order to obtain detector information.
 36 #include "B03ImportanceDetectorConstruction.hh"
 37 
 38 #include "G4RunManager.hh"
 39 #include "G4THitsMap.hh"
 40 #include "G4UnitsTable.hh"
 41 
 42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 43 
 44 // B03RunAction
 45 //
 46 //
 47 //
 48 
 49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 50 
 51 // Constructor
 52 B03RunAction::B03RunAction()
 53   : G4UserRunAction(),
 54     //  fFieldName(15),
 55     fFieldValue(14)
 56 {
 57   // - Prepare data member for B03Run.
 58   //   vector represents a list of MultiFunctionalDetector names.
 59   fSDName.push_back(G4String("ConcreteSD"));
 60 }
 61 
 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 63 
 64 // Destructor.
 65 B03RunAction::~B03RunAction()
 66 {
 67   fSDName.clear();
 68 }
 69 
 70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 71 
 72 G4Run* B03RunAction::GenerateRun()
 73 {
 74   // Generate new RUN object, which is specially
 75   // dedicated for MultiFunctionalDetector scheme.
 76   //  Detail description can be found in B03Run.hh/cc.
 77   return new B03Run(fSDName);
 78 }
 79 
 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 81 
 82 void B03RunAction::BeginOfRunAction(const G4Run* aRun)
 83 {
 84   G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl;
 85 }
 86 
 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 88 
 89 void B03RunAction::EndOfRunAction(const G4Run* aRun)
 90 {
 91   G4cout << " ###### EndOfRunAction  " << G4endl;
 92   //- B03Run object.
 93   B03Run* b02Run = (B03Run*)aRun;
 94   //--- Dump all socred quantities involved in B03Run.
 95   // b02Run->DumpAllScorer();
 96   //---
 97   G4RunManager* mgr = G4RunManager::GetRunManager();
 98   //
 99 
100   for (G4int i = 0; i < (G4int)fSDName.size(); i++) {
101     const G4VUserDetectorConstruction* vdet = mgr->GetUserDetectorConstruction();
102     //    B03DetectorConstruction* bdet = (B03DetectorConstruction*)vdet;
103     B03ImportanceDetectorConstruction* bdet = (B03ImportanceDetectorConstruction*)vdet;
104     //
105 
106     //---------------------------------------------
107     // Dump accumulated quantities for this RUN.
108     //  (Display only central region of x-y plane)
109     //      0       ConcreteSD/Collisions
110     //      1       ConcreteSD/CollWeight
111     //      2       ConcreteSD/Population
112     //      3       ConcreteSD/TrackEnter
113     //      4       ConcreteSD/SL
114     //      5       ConcreteSD/SLW
115     //      6       ConcreteSD/SLWE
116     //      7       ConcreteSD/SLW_V
117     //      8       ConcreteSD/SLWE_V
118     //---------------------------------------------
119     G4THitsMap<G4double>* Collisions = b02Run->GetHitsMap(fSDName[i] + "/Collisions");
120     G4THitsMap<G4double>* CollWeight = b02Run->GetHitsMap(fSDName[i] + "/CollWeight");
121     G4THitsMap<G4double>* Population = b02Run->GetHitsMap(fSDName[i] + "/Population");
122     G4THitsMap<G4double>* TrackEnter = b02Run->GetHitsMap(fSDName[i] + "/TrackEnter");
123     G4THitsMap<G4double>* SL = b02Run->GetHitsMap(fSDName[i] + "/SL");
124     G4THitsMap<G4double>* SLW = b02Run->GetHitsMap(fSDName[i] + "/SLW");
125     G4THitsMap<G4double>* SLWE = b02Run->GetHitsMap(fSDName[i] + "/SLWE");
126     G4THitsMap<G4double>* SLW_V = b02Run->GetHitsMap(fSDName[i] + "/SLW_V");
127     G4THitsMap<G4double>* SLWE_V = b02Run->GetHitsMap(fSDName[i] + "/SLWE_V");
128 
129     if (IsMaster()) {
130       G4cout << "\n--------------------End of Global Run-----------------------" << G4endl;
131       G4cout << " Number of event processed : " << aRun->GetNumberOfEvent() << G4endl;
132     }
133     else {
134       G4cout << "\n--------------------End of Local Run------------------------" << G4endl;
135       G4cout << " Number of event processed : " << aRun->GetNumberOfEvent() << G4endl;
136     }
137 
138     G4cout << "=============================================================" << G4endl;
139     G4cout << "=============================================================" << G4endl;
140 
141     std::ostream* myout = &G4cout;
142     PrintHeader(myout);
143 
144     for (G4int iz = 0; iz < 20; iz++) {
145       G4double* SumCollisions = (*Collisions)[iz];
146       G4double* SumCollWeight = (*CollWeight)[iz];
147       G4double* Populations = (*Population)[iz];
148       G4double* TrackEnters = (*TrackEnter)[iz];
149       G4double* SLs = (*SL)[iz];
150       G4double* SLWs = (*SLW)[iz];
151       G4double* SLWEs = (*SLWE)[iz];
152       G4double* SLW_Vs = (*SLW_V)[iz];
153       G4double* SLWE_Vs = (*SLWE_V)[iz];
154       if (!SumCollisions) SumCollisions = new G4double(0.0);
155       if (!SumCollWeight) SumCollWeight = new G4double(0.0);
156       if (!Populations) Populations = new G4double(0.0);
157       if (!TrackEnters) {
158         G4cout << " NO TRACKS - WHY? " << G4endl;
159         TrackEnters = new G4double(0.0);
160       }
161       if (!SLs) SLs = new G4double(0.0);
162       if (!SLWs) SLWs = new G4double(0.0);
163       if (!SLWEs) SLWEs = new G4double(0.0);
164       if (!SLW_Vs) SLW_Vs = new G4double(0.0);
165       if (!SLWE_Vs) SLWE_Vs = new G4double(0.0);
166       G4double NumWeightedEnergy = 0.0;
167       G4double FluxWeightedEnergy = 0.0;
168       G4double AverageTrackWeight = 0.0;
169       if (*SLW_Vs != 0.) NumWeightedEnergy = (*SLWE_Vs) / (*SLW_Vs);
170       if (*SLWs != 0.) FluxWeightedEnergy = (*SLWEs) / (*SLWs);
171       if (*SLs != 0.) AverageTrackWeight = (*SLWs) / (*SLs);
172       G4String cname = bdet->GetCellName(iz);
173       G4cout << std::setw(fFieldValue) << cname << " |" << std::setw(fFieldValue) << (*TrackEnters)
174              << " |" << std::setw(fFieldValue) << (*Populations) << " |" << std::setw(fFieldValue)
175              << (*SumCollisions) << " |" << std::setw(fFieldValue) << (*SumCollWeight) << " |"
176              << std::setw(fFieldValue) << NumWeightedEnergy << " |" << std::setw(fFieldValue)
177              << FluxWeightedEnergy << " |" << std::setw(fFieldValue) << AverageTrackWeight << " |"
178              << std::setw(fFieldValue) << (*SLs) << " |" << std::setw(fFieldValue) << (*SLWs)
179              << " |" << std::setw(fFieldValue) << (*SLW_Vs) << " |" << std::setw(fFieldValue)
180              << (*SLWEs) << " |" << std::setw(fFieldValue) << (*SLWE_Vs) << " |" << G4endl;
181     }
182     G4cout << "=============================================" << G4endl;
183   }
184 }
185 
186 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
187 
188 void B03RunAction::PrintHeader(std::ostream* out)
189 {
190   std::vector<G4String> vecScoreName;
191   vecScoreName.push_back("Tr.Entering");
192   vecScoreName.push_back("Population");
193   vecScoreName.push_back("Collisions");
194   vecScoreName.push_back("Coll*WGT");
195   vecScoreName.push_back("NumWGTedE");
196   vecScoreName.push_back("FluxWGTedE");
197   vecScoreName.push_back("Av.Tr.WGT");
198   vecScoreName.push_back("SL");
199   vecScoreName.push_back("SLW");
200   vecScoreName.push_back("SLW_v");
201   vecScoreName.push_back("SLWE");
202   vecScoreName.push_back("SLWE_v");
203 
204   // head line
205   // std::string vname = FillString("Volume", ' ', FieldName+1);
206   //*out << vname << '|';
207   std::string vname;
208   *out << std::setw(fFieldValue) << "Volume"
209        << " |";
210   for (std::vector<G4String>::iterator it = vecScoreName.begin(); it != vecScoreName.end(); it++) {
211     // vname = FillString((*it),
212     //                       ' ',
213     //                       fFieldValue+1,
214     //                       false);
215     //    *out << vname << '|';
216     *out << std::setw(fFieldValue) << (*it) << " |";
217   }
218   *out << G4endl;
219 }
220 
221 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
222 
223 std::string B03RunAction::FillString(const std::string& name, char c, G4int n, G4bool back)
224 {
225   std::string fname("");
226   G4int k = n - name.size();
227   if (k > 0) {
228     if (back) {
229       fname = name;
230       fname += std::string(k, c);
231     }
232     else {
233       fname = std::string(k, c);
234       fname += name;
235     }
236   }
237   else {
238     fname = name;
239   }
240   return fname;
241 }
242 
243 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
244