ATLAS Offline Software
Loading...
Searching...
No Matches
Geant4SetupChecker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// My class header file
7
8// For getting information out of Geant4
9#include "G4LogicalVolumeStore.hh"
10#include "G4PhysicalVolumeStore.hh"
11#include "G4RegionStore.hh"
12#include "G4FastSimulationManager.hh"
13#include "G4Region.hh"
14#include "globals.hh"
15
16// For reference file reading
17#include <fstream>
18#include <sstream>
19
20namespace G4UA{
21
22Geant4SetupChecker::Geant4SetupChecker(const std::string& file_location, const bool test=true) : m_file_location(file_location) , m_test(test) {;
23}
24
26
27 // Print the sizes of several stores
28 G4LogicalVolumeStore* g4_logical_volume_store = G4LogicalVolumeStore::GetInstance();
29 G4PhysicalVolumeStore* g4_physical_volume_store = G4PhysicalVolumeStore::GetInstance();
30 G4RegionStore* g4_region_store = G4RegionStore::GetInstance();
31
32 // For each region: GetNumberOfMaterials GetFastSimulationManager ( GetFastSimulationModelList().size() )
33
34 // Might be nice to get at some kind of field information? Stepper?
35// G4TransportationManager* g4_transportation_manager = G4TransportationManager::GetTransportationManager();
36
37 if (m_test){
38 // open a file for comparing these numbers to
39 std::ifstream infile(m_file_location);
40 for (std::string line; std::getline(infile, line); ){
41 std::istringstream in(line);
42 std::string id;
43 in >> id;
44 // Basic geometry counts
45 if ("Counts"==id){
46 unsigned int lvs=0,pvs=0,regs=0;
47 in >> lvs >> pvs >> regs;
48 if (lvs!=g4_logical_volume_store->size()){
49 G4ExceptionDescription ed;
50 ed << "ERROR! Reference had " << lvs << " and this setup has " << g4_logical_volume_store->size() << " logical volumes" << G4endl;
51 G4Exception("Geant4SetupChecker","LogVolMismatch",FatalException,ed);
52 abort();
53 }
54 if (pvs!=g4_physical_volume_store->size()){
55 G4ExceptionDescription ed;
56 ed << "ERROR! Reference had " << pvs << " and this setup has " << g4_physical_volume_store->size() << " physical volumes" << G4endl;
57 G4Exception("Geant4SetupChecker","PhysVolMismatch",FatalException,ed);
58 abort();
59 }
60 if (regs!=g4_region_store->size()){
61 G4ExceptionDescription ed;
62 ed << "ERROR! Reference had " << regs << " and this setup has " << g4_region_store->size() << " regions" << G4endl;
63 G4Exception("Geant4SetupChecker","RegionMismatch",FatalException,ed);
64 abort();
65 }
66 } // This was the basic geometry counting part
67 else { // This is a region - check materials and fast sim
68 G4Region* areg = g4_region_store->GetRegion(id);
69 if (!areg){
70 G4ExceptionDescription ed;
71 ed << "ERROR! Reference had region named " << id << "that is not in this configuration, or has changed name" << G4endl;
72 G4Exception("Geant4SetupChecker","RegionNotFound",FatalException,ed);
73 abort();
74 }
75 unsigned int nmat=0, nfs=0;
76 in >> nmat >> nfs;
77 if (nmat!=areg->GetNumberOfMaterials()){
78 G4ExceptionDescription ed;
79 ed << "ERROR! Region " << id << " had " << nmat << " materials in ref and " << areg->GetNumberOfMaterials() << " in this setup" << G4endl;
80 G4Exception("Geant4SetupChecker","MaterialMismatch",FatalException,ed);
81 abort();
82 }
83 if ( (!areg->GetFastSimulationManager() && nfs!=0) ||
84 ( areg->GetFastSimulationManager() && nfs!=areg->GetFastSimulationManager()->GetFastSimulationModelList().size()) ){
85 G4ExceptionDescription ed;
86 ed << "ERROR! Region " << id << " had " << nfs << " fast sims in ref and " << (areg->GetFastSimulationManager()?areg->GetFastSimulationManager()->GetFastSimulationModelList().size():0) << " in this setup" << G4endl;
87 G4Exception("Geant4SetupChecker","FastSimMismatch",FatalException,ed);
88 abort();
89 }
90 } // End of region handling
91 } // loop over lines
92 infile.close();
93 G4cout << "All ok!" << G4endl;
94 } // Done with the test!
95 else {
96 std::ofstream outfile(m_file_location);
97 outfile << "Counts " << g4_logical_volume_store->size() << " " << g4_physical_volume_store->size() << " " << g4_region_store->size() << std::endl;
98 // Now go through all the regions
99 for (auto* areg : *g4_region_store){
100 outfile << areg->GetName() << " " << areg->GetNumberOfMaterials() << " " << (areg->GetFastSimulationManager()?areg->GetFastSimulationManager()->GetFastSimulationModelList().size():0) << std::endl;
101 }
102 outfile.close();
103 } // Done with writing a reference file
104}
105
106} // namespace G4UA
Geant4SetupChecker(const std::string &, const bool)
bool m_test
Do you want to write a reference or read a file to check?
std::string m_file_location
File location for reference file.
virtual void BeginOfRunAction(const G4Run *) override