Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
TSRunAction.cc
이 파일의 문서화 페이지로 가기
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 //
28 //
29 //
30 // $Id: TSRunAction.cc 93110 2015-11-05 08:37:42Z jmadsen $
31 //
32 //
33 //
34 //
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37 
38 
39 #include "TSRunAction.hh"
41 
42 #include "G4RunManager.hh"
43 #include "G4Run.hh"
44 #include "G4Timer.hh"
45 
46 #include "TSRun.hh"
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
50 
52 : fDetector(TSDetectorConstruction::Instance()),
53  fName(fDetector->GetMFDName())
54 { }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
57 
59 { }
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
64 {
65  return new TSRun(fName);
66 }
67 
68 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69 
71 {
72  G4int evts_to_process = aRun->GetNumberOfEventToBeProcessed();
73  G4RunManager::GetRunManager()->SetPrintProgress((evts_to_process > 100)
74  ? evts_to_process/100
75  : 1);
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
82 
83  if(IsMaster())
84  {
85  G4cout << " ###### EndOfTSRunAction ###### " << G4endl;
86 
87  aRun->GetNumberOfEvent();
88  std::ofstream fileout;
89  G4String fname = "";
90  std::stringstream separator;
91 
92  separator
93  << "============================================================";
94 
95  typedef std::set<G4int> IDSet_t;
96  IDSet_t IDs;
97 
98  //- TSRun object.
99  const TSRun* tsRun = static_cast<const TSRun*>(aRun);
100  //--- Dump all scored quantities involved in TSRun.
101 
102  //---------------------------------------------
103  // Dump accumulated quantities for this RUN.
104  //---------------------------------------------
105  std::vector<G4String> primScorerNames { "EnergyDeposit",
106  "NumberOfSteps" };
107  std::vector<G4String> fnames { "mfd_tl", "mfd_tg" };
108  std::vector<G4double> units { CLHEP::eV, CLHEP::keV, 1, 1 };
109  std::vector<G4String> unitstr { "keV", "steps" };
110 
111  for(unsigned i = 0; i < primScorerNames.size(); ++i)
112  {
113  for(unsigned j = 0; j < fnames.size(); ++j)
114  {
115  //----------------------------------------------------------------//
116  auto print = [] (std::ostream& fout,
118  G4double unit1, G4double unit2, G4String unit2str)
119  {
120  if(fout)
121  fout << first
122  << " " << second/unit1
123  << G4endl;
124 
125  G4cout
126  << " " << std::setw(10) << first
127  << " " << std::setw(15) << std::setprecision(6)
128  << std::fixed << second/unit2 << " " << unit2str
129  << G4endl;
130  G4cout.unsetf(std::ios::fixed);
131  };
132  //----------------------------------------------------------------//
133 
134  fname = fnames.at(j) + "_" + primScorerNames.at(i) + ".out";
135  fileout.open(fname);
136  G4cout << separator.str() << G4endl;
137  G4cout << " opened file " << fname << " for output" << G4endl;
138  G4cout << separator.str() << G4endl;
139 
140  G4bool valid = true;
141  if(j == 0)
142  {
143  G4THitsMap<G4double>* hitmap
144  = tsRun->GetHitsMap(fName + "/" + primScorerNames.at(i));
145  if(hitmap && hitmap->GetMap()->size() != 0)
146  {
147  for(auto itr = hitmap->GetMap()->begin();
148  itr != hitmap->GetMap()->end(); itr++)
149  {
150  IDs.insert(itr->first);
151  std::get<0>(fTypeCompare[primScorerNames.at(i)][itr->first])
152  = *itr->second/units.at(i);
153  print(fileout, itr->first, *itr->second,
154  units.at(i), units.at(i+1), unitstr.at(i));
155  }
156  } else {
157  valid = false;
158  }
159  if(!valid)
160  {
161  G4Exception("TSRunAction", "000", JustWarning,
162  G4String(primScorerNames.at(i) +
163  " HitsMap is either not "
164  "created or the HitsMap was empty").c_str());
165  }
166  } else {
168  = tsRun->GetAtomicHitsMap(fName + "/" +
169  primScorerNames.at(i));
170  if(hitmap && hitmap->GetMap()->size() != 0)
171  {
172  for(auto itr = hitmap->GetMap()->begin();
173  itr != hitmap->GetMap()->end(); itr++)
174  {
175  IDs.insert(itr->first);
176  std::get<1>(fTypeCompare[primScorerNames.at(i)][itr->first])
177  = *itr->second/units.at(i);
178  print(fileout, itr->first, *itr->second,
179  units.at(i), units.at(i+1), unitstr.at(i));
180  }
181  } else {
182  valid = false;
183  }
184  if(!valid)
185  {
186  G4Exception("TSRunAction", "001", JustWarning,
187  G4String(primScorerNames.at(i) +
188  " HitsMap is either not "
189  "created or the HitsMap was empty").c_str());
190  }
191  }
192 
193  fileout.close();
194  G4cout << separator.str() << G4endl;
195  G4cout << " closed file " << fname << " for output" << G4endl;
196  }
197  // add the mutex data
198  TSRun::MutexHitsMap_t* hitmap
199  = tsRun->GetMutexHitsMap(fName + "/" +
200  primScorerNames.at(i));
201  if(hitmap && hitmap->size() != 0)
202  {
203  for(auto itr = hitmap->begin();
204  itr != hitmap->end(); itr++)
205  {
206  IDs.insert(itr->first);
207  std::get<2>(fTypeCompare[primScorerNames.at(i)][itr->first])
208  = itr->second/units.at(i);
209  }
210  }
211 
212  }
213 
214  //--------------------------------------------------------------------//
215  // Check that the values are equivalent and there are no
216  // IDs in one container that aren't in another
217  //--------------------------------------------------------------------//
218 
219  fname = "mfd_diff.out";
220  fileout.open(fname);
221 
222  G4cout << separator.str() << G4endl;
223  G4cout << " opened file " << fname << " for difference output" << G4endl;
224  G4cout << separator.str() << G4endl;
225 
226  fileout
227  << " " << std::setw(10) << "ID"
228  << " "
229  << std::setw(30) << std::setprecision(12) << std::fixed
230  << "MFD value"
231  << " "
232  << std::setw(30) << std::setprecision(12) << std::fixed
233  << "Atomic Hits Map value"
234  << " "
235  << std::setw(30) << std::setprecision(8) << std::scientific
236  << "Difference"
237  << " "
238  << std::setw(30) << std::setprecision(8) << std::scientific
239  << "Diff (MFD - MUTEXED)"
240  << " "
241  << std::setw(30) << std::setprecision(8) << std::scientific
242  << "Diff (ATOM_HIT_MAP - MUTEXED)"
243  << G4endl << G4endl;
244 
245  for(auto itr1 = fTypeCompare.begin();
246  itr1 != fTypeCompare.end(); ++itr1)
247  {
248  fileout << "\n\nType = " << itr1->first << "\n" << G4endl;
249  for(auto itr2 = itr1->second.begin();
250  itr2 != itr1->second.end(); ++itr2)
251  {
252  G4double d01
253  = std::fabs(std::get<0>(itr2->second) -
254  std::get<1>(itr2->second));
255  G4double d02
256  = std::fabs(std::get<0>(itr2->second) -
257  std::get<2>(itr2->second));
258  G4double d03
259  = std::fabs(std::get<1>(itr2->second) -
260  std::get<2>(itr2->second));
261 
262 
263  auto _print_diff = [&] (const G4double& _dval)
264  {
265  if(_dval > 0.0)
266  fileout << std::setprecision(8) << std::scientific
267  << std::setw(30) << _dval << " ";
268  else
269  fileout << std::setprecision(1) << std::fixed
270  << std::setw(30) << _dval << " ";
271  };
272 
273  fileout
274  << " " << std::setw(10) << itr2->first
275  << " "
276  << std::setw(30) << std::setprecision(12) << std::fixed
277  << std::get<0>(itr2->second)
278  << " "
279  << std::setw(30) << std::setprecision(12) << std::fixed
280  << std::get<1>(itr2->second)
281  << " ";
282 
283  _print_diff(d01);
284  _print_diff(d02);
285  _print_diff(d03);
286 
287  fileout << G4endl;
288 
289  }
290  }
291 
292  fileout.close();
293  G4cout << " closed file " << fname << " for difference output" << G4endl;
294  G4cout << separator.str() << G4endl;
295  }
296 
297 
298 }
299 
300 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
301 
302 
303 
304 
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
Definition of the TSRun class.
void print(G4double elem)
Definition of the TSRunAction class.
container_type * GetMap() const
#define G4endl
Definition: G4ios.hh:61
Definition of the TSActionInitialization class.
static constexpr double second
Definition: G4SIunits.hh:157
MutexHitsMap_t * GetMutexHitsMap(const G4String &) const
Definition: TSRun.cc:260
virtual void EndOfRunAction(const G4Run *)
Definition: TSRunAction.cc:80
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
TypeCompare_t fTypeCompare
Definition: TSRunAction.hh:71
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
Definition: TSRun.hh:70
std::map< G4int, G4double > MutexHitsMap_t
Definition: TSRun.hh:73
virtual G4Run * GenerateRun()
Definition: TSRunAction.cc:63
virtual ~TSRunAction()
Definition: TSRunAction.cc:58
static constexpr double eV
G4String fName
Definition: G4AttUtils.hh:55
G4bool IsMaster() const
Definition: G4Run.hh:46
G4int GetNumberOfEventToBeProcessed() const
Definition: G4Run.hh:83
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4TAtomicHitsMap< G4double > * GetAtomicHitsMap(const G4String &) const
Definition: TSRun.cc:241
int G4int
Definition: G4Types.hh:78
G4String fName
Definition: TSRunAction.hh:70
G4GLOB_DLL std::ostream G4cout
G4THitsMap< G4double > * GetHitsMap(const G4String &collname) const
Definition: TSRun.cc:222
static constexpr double keV
Definition of the TSDetectorConstruction class.
Map_t * GetMap() const
Definition: G4THitsMap.hh:117
virtual void BeginOfRunAction(const G4Run *)
Definition: TSRunAction.cc:70
void SetPrintProgress(G4int i)