Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TSRunAction Class Reference

#include <TSRunAction.hh>

Inheritance diagram for TSRunAction:
Collaboration diagram for TSRunAction:

Public Types

typedef std::tuple< G4double,
G4double, G4double
Compare_t
 
typedef std::map< G4int,
Compare_t
IDcompare_t
 
typedef std::map< G4String,
IDcompare_t
TypeCompare_t
 

Public Member Functions

 TSRunAction ()
 
virtual ~TSRunAction ()
 
virtual void BeginOfRunAction (const G4Run *)
 
virtual void EndOfRunAction (const G4Run *)
 
virtual G4RunGenerateRun ()
 
- Public Member Functions inherited from G4UserRunAction
 G4UserRunAction ()
 
virtual ~G4UserRunAction ()
 
virtual void SetMaster (G4bool val=true)
 
G4bool IsMaster () const
 

Additional Inherited Members

- Protected Attributes inherited from G4UserRunAction
G4bool isMaster
 

Detailed Description

Definition at line 52 of file TSRunAction.hh.

Member Typedef Documentation

Definition at line 55 of file TSRunAction.hh.

Definition at line 56 of file TSRunAction.hh.

Definition at line 57 of file TSRunAction.hh.

Constructor & Destructor Documentation

TSRunAction::TSRunAction ( )

Definition at line 51 of file TSRunAction.cc.

53  fName(fDetector->GetMFDName())
54 { }
static TSDetectorConstruction * Instance()
const G4String & GetMFDName() const
TSRunAction::~TSRunAction ( )
virtual

Definition at line 58 of file TSRunAction.cc.

59 { }

Member Function Documentation

void TSRunAction::BeginOfRunAction ( const G4Run aRun)
virtual

Reimplemented from G4UserRunAction.

Definition at line 70 of file TSRunAction.cc.

71 {
72  G4int evts_to_process = aRun->GetNumberOfEventToBeProcessed();
73  G4RunManager::GetRunManager()->SetPrintProgress((evts_to_process > 100)
74  ? evts_to_process/100
75  : 1);
76 }
void SetPrintProgress(G4int i)
int G4int
Definition: G4Types.hh:78
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
G4int GetNumberOfEventToBeProcessed() const
Definition: G4Run.hh:83

Here is the call graph for this function:

void TSRunAction::EndOfRunAction ( const G4Run aRun)
virtual

Reimplemented from G4UserRunAction.

Definition at line 80 of file TSRunAction.cc.

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  } else {
161  = tsRun->GetAtomicHitsMap(fName + "/" +
162  primScorerNames.at(i));
163  if(hitmap && hitmap->GetMap()->size() != 0)
164  {
165  for(auto itr = hitmap->GetMap()->begin();
166  itr != hitmap->GetMap()->end(); itr++)
167  {
168  IDs.insert(itr->first);
169  std::get<1>(fTypeCompare[primScorerNames.at(i)][itr->first])
170  = *itr->second/units.at(i);
171  print(fileout, itr->first, *itr->second,
172  units.at(i), units.at(i+1), unitstr.at(i));
173  }
174  } else {
175  valid = false;
176  }
177  if(!valid)
178  {
179  G4Exception("TSRunAction", "000", JustWarning,
180  G4String(primScorerNames.at(i) +
181  " HitsMap is either not "
182  "created or the HitsMap was empty").c_str());
183  }
184  }
185 
186  fileout.close();
187  G4cout << separator.str() << G4endl;
188  G4cout << " closed file " << fname << " for output" << G4endl;
189  }
190  // add the mutex data
191  TSRun::MutexHitsMap_t* hitmap
192  = tsRun->GetMutexHitsMap(fName + "/" +
193  primScorerNames.at(i));
194  if(hitmap && hitmap->size() != 0)
195  {
196  for(auto itr = hitmap->begin();
197  itr != hitmap->end(); itr++)
198  {
199  IDs.insert(itr->first);
200  std::get<2>(fTypeCompare[primScorerNames.at(i)][itr->first])
201  = itr->second/units.at(i);
202  }
203  }
204 
205  }
206 
207  //--------------------------------------------------------------------//
208  // Check that the values are equivalent and there are no
209  // IDs in one container that aren't in another
210  //--------------------------------------------------------------------//
211 
212  fname = "mfd_diff.out";
213  fileout.open(fname);
214 
215  G4cout << separator.str() << G4endl;
216  G4cout << " opened file " << fname << " for difference output" << G4endl;
217  G4cout << separator.str() << G4endl;
218 
219  fileout
220  << " " << std::setw(10) << "ID"
221  << " "
222  << std::setw(30) << std::setprecision(12) << std::fixed
223  << "MFD value"
224  << " "
225  << std::setw(30) << std::setprecision(12) << std::fixed
226  << "Atomic Hits Map value"
227  << " "
228  << std::setw(30) << std::setprecision(12) << std::fixed
229  << "Difference"
230  << " "
231  << std::setw(30) << std::setprecision(12) << std::fixed
232  << "Diff (MFD - MUTEXED)"
233  << " "
234  << std::setw(30) << std::setprecision(12) << std::fixed
235  << "Diff (ATOM_HIT_MAP - MUTEXED)"
236  << G4endl << G4endl;
237 
238  for(auto itr1 = fTypeCompare.begin();
239  itr1 != fTypeCompare.end(); ++itr1)
240  {
241  fileout << "\n\nType = " << itr1->first << "\n" << G4endl;
242  for(auto itr2 = itr1->second.begin();
243  itr2 != itr1->second.end(); ++itr2)
244  {
245  fileout
246  << " " << std::setw(10) << itr2->first
247  << " "
248  << std::setw(30) << std::setprecision(12) << std::fixed
249  << std::get<0>(itr2->second)
250  << " "
251  << std::setw(30) << std::setprecision(12) << std::fixed
252  << std::get<1>(itr2->second)
253  << " "
254  << std::setw(30) << std::setprecision(12) << std::fixed
255  << (std::fabs(std::get<0>(itr2->second) - std::get<1>(itr2->second)))
256  << " "
257  << std::setw(30) << std::setprecision(12) << std::fixed
258  << (std::fabs(std::get<0>(itr2->second) - std::get<2>(itr2->second)))
259  << " "
260  << std::setw(30) << std::setprecision(12) << std::fixed
261  << (std::fabs(std::get<1>(itr2->second) - std::get<2>(itr2->second)))
262  << G4endl;
263 
264  }
265  }
266 
267  fileout.close();
268  G4cout << " closed file " << fname << " for difference output" << G4endl;
269  G4cout << separator.str() << G4endl;
270 
271  }
272 
273 
274 }
static constexpr double keV
MutexHitsMap_t * GetMutexHitsMap(const G4String &) const
Definition: TSRun.cc:250
static constexpr double second
Definition: G4SIunits.hh:157
Definition: TSRun.hh:70
int G4int
Definition: G4Types.hh:78
G4THitsMap< G4double > * GetHitsMap(const G4String &collname) const
Definition: TSRun.cc:212
G4GLOB_DLL std::ostream G4cout
G4int GetNumberOfEvent() const
Definition: G4Run.hh:79
bool G4bool
Definition: G4Types.hh:79
std::map< G4int, G4double > MutexHitsMap_t
Definition: TSRun.hh:73
G4bool IsMaster() const
void print(G4double elem)
static constexpr double eV
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
container_type * GetMap() const
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:99
#define G4endl
Definition: G4ios.hh:61
string fname
Definition: test.py:308
G4TAtomicHitsMap< G4double > * GetAtomicHitsMap(const G4String &) const
Definition: TSRun.cc:231
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

G4Run * TSRunAction::GenerateRun ( void  )
virtual

Reimplemented from G4UserRunAction.

Definition at line 63 of file TSRunAction.cc.

64 {
65  return new TSRun(fName);
66 }
Definition: TSRun.hh:70

The documentation for this class was generated from the following files: