Skip to content

Commit

Permalink
updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
martinunland committed Aug 28, 2024
1 parent 840fd48 commit 775673d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
6 changes: 3 additions & 3 deletions common/framework/include/OMSimInputData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public:
log_trace("Fetching parameter {} in key {}", pParameter, pKey);
try
{
const T lValue = mTable.at(pKey).get<T>(pParameter);
const T lValue = m_table.at(pKey).get<T>(pParameter);
return lValue;
}

Expand Down Expand Up @@ -160,8 +160,8 @@ public:
};

private:
std::map<G4String, boost::property_tree::ptree> mTable; ///< A table mapping keys to property trees.
std::map<G4String, G4String> mKeyFileOrigin; ///< A table mapping keys to original file name.
std::map<G4String, boost::property_tree::ptree> m_table; ///< A table mapping keys to property trees.
std::map<G4String, G4String> m_keyToFileName; ///< A table mapping keys to original file name.
};

/**
Expand Down
12 changes: 6 additions & 6 deletions common/framework/src/OMSimInputData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pt::ptree ParameterTable::appendAndReturnTree(G4String p_fileName)
pt::ptree lJsonTree;
pt::read_json(p_fileName, lJsonTree);
const G4String lName = lJsonTree.get<G4String>("jName");
mTable[lName] = lJsonTree;
mKeyFileOrigin[lName] = p_fileName;
m_table[lName] = lJsonTree;
m_keyToFileName[lName] = p_fileName;
log_trace("Key {} added to dictionary from file {}.", lName, p_fileName);
return lJsonTree;
}
Expand All @@ -45,11 +45,11 @@ G4double ParameterTable::getValueWithUnit(G4String pKey, G4String pParameter)
}

// Get the sub-tree for the provided key
const auto &lSubTree = mTable.at(pKey);
const auto &lSubTree = m_table.at(pKey);

if (!lSubTree.get_child_optional(pParameter))
{
G4String lErrorLog = "Table in key '" + pKey + "' has no parameter '" + pParameter + "'. Check file '" + mKeyFileOrigin.at(pKey) + "'";
G4String lErrorLog = "Table in key '" + pKey + "' has no parameter '" + pParameter + "'. Check file '" + m_keyToFileName.at(pKey) + "'";
log_error(lErrorLog);
throw std::runtime_error(lErrorLog);
}
Expand Down Expand Up @@ -87,7 +87,7 @@ G4double ParameterTable::getValueWithUnit(G4String pKey, G4String pParameter)
pt::ptree ParameterTable::getJSONTree(G4String pKey)
{
if (checkIfTreeNameInTable(pKey))
return mTable.at(pKey);
return m_table.at(pKey);
else
log_critical("Key not found in table");
return boost::property_tree::ptree(); // Return an empty ptree
Expand All @@ -102,7 +102,7 @@ pt::ptree ParameterTable::getJSONTree(G4String pKey)
G4bool ParameterTable::checkIfTreeNameInTable(G4String pKey)
{
log_trace("Checking if tree {} is in table...", pKey);
const G4int lFound = mTable.count(pKey);
const G4int lFound = m_table.count(pKey);
if (lFound > 0)
return true;
else
Expand Down
42 changes: 35 additions & 7 deletions documentation/extra_doc/0_common.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,47 @@ This framework offers tools to simplify geometry construction and material defin

## Materials and User Data

User-defined material data are stored in JSON files under `/common/data` to minimize file length.
User-defined material data are stored in JSON files under `/common/data` to avoid filling source code with numbers.
The `OMSimInputData` class (see `OMSimInputData.hh`) is responsible for processing these files and loading the material properties into the Geant4 framework. It uses the `OMSimMaterialHandler` class to handle the specifics of material creation and property setting.

The `OMSimInputData` (see `OMSimInputData.hh`) loads these properties directly into the Geant4 framework. Materials loaded via this class can be retrieved using Geant4's conventional method `G4Material::GetMaterial`, but the framework also provides the wrapper `OMSimInputData::getMaterial` to handle default parameters.
### Material Handling

The class also provides an analogue method for optical surfaces `OMSimInputData::getOpticalSurface` which does not exist in Geant4.
The `OMSimMaterialHandler` class is the core component for creating and modifying materials. It provides several key methods:

Since different materials have different types of properties, the data is loaded in multiple ways. These different material types are defined in `OMSimDataFileTypes.hh`.
- `ProcessMaterial()`: Creates a new material or modifies an existing one based on the data in the input file.
- `ProcessSurface()`: Processes and returns an optical surface defined in the input file.
- `ProcessExtraProperties()`: Adds additional properties to an existing material.
- `ProcessSpecial(ProcessorFunction p_processor)`: Handles special material types like IceCube ice or scintillators that require custom processing.

Additionally, geometry data used during PMT construction are also stored in JSON files (`/common/data/PMTs`). These are saved in a "tree" (essentially a dictionary containing the JSON file's keys and values) in `OMSimInputData::mTable`.
Materials created via this class can be retrieved using Geant4's conventional method `G4Material::GetMaterial`. The `OMSimInputData` class also provides a wrapper method `getMaterial` to handle default parameters and special "argument materials".

This approach was adopted because various PMTs are constructed similarly, eliminating the need to define a unique class for each PMT type, as is done for the optical modules.
### Optical Surfaces

If you wish to load additional data, you can either define a new type in OMSimDataFileTypes or use a json file to load it into a tree as previously mentioned. For simpler tasks, use the static method `Tools::loadtxt` provided by the [`Tools` namespace](md_extra_doc_2_technicalities.html#autotoc_md20).
For optical surfaces, `OMSimInputData` provides the method `getOpticalSurface`, which doesn't exist in Geant4 by default.

### Special Material Types

Different materials may require different types of properties and processing. The `OMSimMaterialHandler` class can handle various material types, including:

- Standard materials with refractive index and absorption properties
- IceCube ice, where the optical properties are calculated by the selected depth (an arg variable)
- Scintillator materials with complex decay time and yield properties

Special processors for these materials are implemented in separate namespaces (e.g., `IceProcessor`, `ScintillationProcessor`) and can be passed to the `ProcessSpecial` method of `OMSimMaterialHandler`.

### Geometry Data

PMT construction data is also stored in JSON files (`/common/data/PMTs`). This data is loaded into a "tree" (essentially a dictionary containing the JSON file's keys and values) in `OMSimInputData::m_table`. This approach allows for flexible PMT construction without defining a unique class for each PMT type.

### Adding New Data

To add new material data:

1. Create a new JSON file in the appropriate directory under `/common/data`.
2. If the material requires special processing, you may need to create a new processor function or namespace.
3. Update `OMSimInputData::processFile` to handle the new file type if necessary.

For simpler tasks, you can use the static method `Tools::loadtxt` provided by the [`Tools` namespace](md_extra_doc_2_technicalities.html#autotoc_md20).

---

Expand Down

0 comments on commit 775673d

Please sign in to comment.