```{image} ../../src/orangecontrib/ewoks3dxrd/icons/indexing.svg
:alt: Index Grains Widget Icon
:class: widget-title-icon
```
# Indexing Widget

The Index Grains widget utilizes the ImageD11 indexing engine to 
find the orientation of individual grains within your sample. 
It processes the filtered 3D peaks to generate a list of $UBI$ matrices, 
which represent the grain map in reciprocal space.

## Functionality
This widget allows you to:
1. **Generate Grain:** Search for crystal orientations that satisfy the diffraction geometry.
2. **Score and Validate:** Evaluate the quality of found grains based on how many theoretical peaks they "explain" (i.e. the peaks are considered as originating from the grain).


## User Interface
![Image showing the initial state of the indexer widget](../_static/tuto/initial_deterministic_indexing.png)

## Control Panel

The left panel contains the configuration and execution logic.

### Indexing Parameters
These settings define the logic used to pair peaks and form orientations. 
```{attention} Note: 
The parameters visible in the GUI are a subset of the ImageD11 indexing scheme optimized for reliability.
```
1. **Rings for grain generation:** The specific rings used to generate potential grain orientations. At least two rings are required.
2. **Scoring Rings:** A (usually larger) set of rings used to validate the found orientations. 
    Grains that don't explain enough peaks in these rings are discarded.
3. **Reciprocal Dist Tol ($ds$​ Tol):** The maximum radial error allowed when assigning a peak to a specific grain.
4. **HKL Tolerances:** Miller indices tolerances (in decreasing order) used during the refinement of the orientation matrix ($UBI$).
5. **Lattice File & Wavelength:** Automatically forwarded from previous tasks to provide the physical scale for indexing.

### Search Constraints
* **Max Grains:** An optional limit to stop the search after a specific number of grains are found (useful for high-speed testing).

### Execution Control
* **Process Group Name:** The HDF5/Nexus path for the generated UBI matrices (defaults to `indexed_grains`).
    ```{tip}
        Note: For multiphase samples, use unique names like grains_phase_A and grains_phase_B.
    ```
* **Index Grains:** Will find the grains (i.e list of $UBI$ matrices)

## Example Usage
1. Connect the widget to the output of an Index Filter (or Intensity Filter) or provide the respective HDF5/Nexus data group path.
2. Verify that Indexing Rings includes at least two strong, non-overlapping rings (e.g., $(0, 1)$).
3. Set Scoring Rings to include all visible rings in your data (e.g., $(0, 1, 2, 3, 4)$).
4. Click Find Grains and monitor the output to see the list of identified crystal orientations

![Image showing the result of the indexer widget](../_static/tuto/deterministic_indexing.png)