# Workspace Unit Cell Fit
The Workspace Unit Cell Fit tool aggregates unit-cell parameters (a, b, c, α, β, γ) from all indexed datasets in the workspace, displays them as histograms, and lets you fit a Gaussian to any parameter by dragging a range selector. The fitted mean can then be written back as a workspace-wide refined cell, which the Merge window can use for statistics instead of the per-dataset indexing cell.

## Requirements
- At least one indexing or ICI run must exist for a dataset in the workspace. The newest run per dataset is used automatically.
## How to use
Open **Tools → Workspace unit cell fit**. COSEDA scans all loaded datasets for their latest stream file, parses the indexed unit-cell parameters, and plots six histograms — one per parameter.
**Fitting a parameter:**
Click and drag horizontally across the peak of interest in any histogram. COSEDA fits a Gaussian to the values within the selected range and overlays the curve in red. The fit result (mean, std, FWHM, N) appears in the label above the plot.
**Writing the result back:**
Once a fit looks good, click **Update workspace refined cell**. COSEDA stores the fitted mean for that parameter in the workspace file. Repeat for each parameter you want to refine. When all six parameters have been fitted, the refined cell becomes available as a **Cell for merge analysis** option in the Merge window Settings tab.
## Controls
| Control | Description |
|---|---|
| **Bins** | Number of histogram bins (5–500, default 60). |
| **One solution per image** | When checked (default), only one indexed solution is taken per frame. For frames with multiple solutions, the **Multi-solution choice** setting decides which one to keep. |
| **Multi-solution choice** | Which solution to keep when a frame has more than one: **Best (most reflections)**, **Highest resolution**, or **Lowest resolution**. |
| **Refresh** | Re-scan the workspace for streams and replot. |
| **Update workspace refined cell** | Write the Gaussian fit mean for the currently selected parameter to the workspace. Enabled only after a successful fit. |
## Reading the histograms
Each histogram bar covers one bin of cell-parameter values across all indexed frames in the workspace. A sharp, symmetric peak indicates a well-determined parameter; a broad or multi-modal distribution suggests variation between crystals or poor indexing for some datasets.
When you fit a range, the selected region is shaded orange, the Gaussian is drawn in red, and the title updates to show the mean and standard deviation. The status line below the plot shows how many workspace files and stream files were loaded and how many total values are in the histograms.
## Outputs
- **Workspace file** — the fitted mean is stored as `# Cell.=` header entries and `# Cell.refined=true`. Existing indexing run cell files are not changed.
- **`coseda_refined_cells/_refined.cell`** — a CrystFEL cell file materialised from the workspace header, written when the refined cell is used downstream (e.g., when the Merge window requests it for `check_hkl`/`compare_hkl`).