Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
martinunland committed Aug 1, 2024
1 parent 1baa737 commit ef701ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
8 changes: 3 additions & 5 deletions documentation/extra_doc/0_common.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 (the original detector construction had over 4,000 lines, mainly due to material properties!).
User-defined material data are stored in JSON files under `/common/data` to minimize file length.

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.

Expand All @@ -17,8 +17,6 @@ Additionally, geometry data used during PMT construction are also stored in JSON

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.

Thus, an instance of `OMSimInputData` is always passed to all classes related to geometry construction (see [geometry](#geometry-construction)).

If you wish to load additional data, you can either define a new type in OMSimDataFileTypes or load it into a tree as previously mentioned. For simpler tasks, use the static method `Tools::loadtxt` provided in `OMSimTools.hh`, which operates similarly to Python's numpy.loadtxt. For example:

```cpp
Expand Down Expand Up @@ -81,7 +79,7 @@ Here's an example of how to properly create and configure sensitive detectors fo

```cpp
for (int i = 0; i < numberOfModules; ++i) {
mDOM* module = new mDOM(mData, false);
mDOM* module = new mDOM(false);
G4String lExtension = "_" + std::to_string(i);
module->placeIt(G4ThreeVector(0, 0, i*3*m), G4RotationMatrix(), mWorldLogical, lExtension); //you have to have unique names
module->configureSensitiveVolume(this);
Expand Down Expand Up @@ -109,7 +107,7 @@ Figure 4: <i>PMT response compared to measurement for different light sources. I

### Hit storage

The absorbed photon data is managed by the `OMSimHitManager` singleton. It maintains a vector of hit information (`HitStats` struct) for each sensitive detector. To analyze and export this data, use the `OMSimHitManager::getSingleThreadHitsOfModule` method to retrieve data for the current thread, or `OMSimHitManager::getMergedHitsOfModule` to obtain merged data from all threads. Note that `OMSimHitManager::getMergedHitsOfModule` works only if `OMSimHitManager::mergeThreadData` has been called (happens at the end of the run when `OMSimRunActio::EndOfRunAction` is called). For analysis or storage at the end of an event, handle each thread separately as events end asynchronously. For practical examples, refer to the methods in `OMSimEffectiveAreaAnalysis` and `OMSimSNAnalysis::writeDataFile`.
The absorbed photon data is managed by the `OMSimHitManager` global instance. It maintains a vector of hit information (`HitStats` struct) for each sensitive detector. To analyze and export this data, use the `OMSimHitManager::getSingleThreadHitsOfModule` method to retrieve data for the current thread, or `OMSimHitManager::getMergedHitsOfModule` to obtain merged data from all threads. Note that `OMSimHitManager::getMergedHitsOfModule` works only if `OMSimHitManager::mergeThreadData` has been called (happens at the end of the run when `OMSimRunActio::EndOfRunAction` is called). For analysis or storage at the end of an event, handle each thread separately as events end asynchronously. For practical examples, refer to the methods in `OMSimEffectiveAreaAnalysis` and `OMSimSNAnalysis::writeDataFile`.

An additional feature allows for the direct application of a QE cut. This ensures that only absorbed photons passing the QE test are retained in `OMSimHitManager`. To enable this feature, provide the "QE_cut" argument via the command line. In this case `OMSimSensitiveDetector::ProcessHits` will call `OMSimPMTResponse::passQE` and break early if it returns false, without storing the photon information.

Expand Down
18 changes: 9 additions & 9 deletions documentation/extra_doc/1_multithreading.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ OMSimHitManager& OMSimHitManager::getInstance()
### Example: OMSimHitManager

The `OMSimHitManager` class demonstrates several thread-safety techniques:
The `OMSimHitManager` class demonstrates several thread-safety techniques for saving data:

```cpp
class OMSimHitManager
Expand All @@ -95,11 +95,11 @@ private:
```

Key features:
- Thread-local storage for hit data (`mThreadData`).
- Mutex for thread synchronization.
- Thread-local storage for hit data (`mThreadData`), each thread will start one
- Mutex (`mMutex`) for thread synchronization.


The `appendHitInfo` method:
The `appendHitInfo` method is used by all threads and uses to the thread-local `mThreadData`:

```cpp
void OMSimHitManager::appendHitInfo(/* parameters */)
Expand All @@ -110,13 +110,14 @@ void OMSimHitManager::appendHitInfo(/* parameters */)
mThreadData = new ThreadLocalData();
}

// Append hit information to thread-local container
// This is thread-safe as each thread has its own mThreadData
// ... append hit information to mThreadData->moduleHits ...
auto &moduleHits = mThreadData->moduleHits[pModuleNumber];
G4int eventID = G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID();
moduleHits.eventId.push_back(eventID);
//...
}
```
The `mergeThreadData` method combines data from all threads:
The `mergeThreadData` method combines data from all threads into a single vector:
```cpp
void OMSimHitManager::mergeThreadData()
Expand Down Expand Up @@ -251,7 +252,6 @@ When implementing new thread-safe containers in Geant4:
By following these guidelines and studying the provided examples, you can create thread-safe containers and classes for your Geant4 simulations, ensuring proper behavior in multi-threaded environments.



## Troubleshooting Multi-threading Issues

When developing new code with multi-threaded simulations in Geant4, you may encounter race conditions or other thread-related issues. Here's a general approach to diagnose and resolve these problems:
Expand Down

0 comments on commit ef701ad

Please sign in to comment.