# dune/lblpwgtools architecture

> Architecture diagram of the GitHub repository dune/lblpwgtools, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dune/lblpwgtools
- Repository: https://github.com/dune/lblpwgtools

## Overview

##### Project type and purpose
- This is an open-source C++ physics‐analysis framework (“CAFAna”) plus a set of command-line tools and scripts used by the DUNE Long Baseline Physics Working Group.
- It provides a core library for histograms, cuts, spectrum loading, oscillation and systematic‐uncertainty handling, plus modules for fitting, prediction, extrapolation, PRISM‐specific analyses, and higher-level executables and scripts that drive end-to-end studies.

##### File structure
- Top-level:
- CAFAna/    ← main CMake project root, subdivided by functionality
- scripts/   ← Python & shell orchestration scripts
- EventSelectionScripts/, PlotScripts/, probabilities/, fcl/ ← auxiliary code and config
- test/, tute/   ← unit & tutorial examples
- Within CAFAna/: each subdirectory is a self-contained CMake target producing a static/shared library or executable:
- Core/        ← foundational data structures & utilities
- Analysis/    ← plot routines, resolution, exposure calculations
- Cuts/        ← event‐selection definitions
- Experiment/  ← χ² & likelihood experiments
- Extrap/      ← extrapolation interfaces & implementations
- Fit/         ← fit engines (Minuit2, Stan, MCMC)
- Prediction/  ← oscillation, interpolation, scale & extrap predictions
- Systs/       ← systematic‐uncertainty definitions & fake data
- Vars/        ← analysis variable definitions
- Utils/       ← small helpers (e.g. EnumIter)
- PRISM/       ← PRISM‐specific analysis & toolchain
- bin/, cafe/  ← command-line applications linking the above
- cmake/       ← custom find scripts & build templates

##### README for additional insights
- Describes how to build (“standalone_configure_and_build.sh”) and external dependencies (ROOT w/ minuit2, GSL, CLHEP, Boost, Stan, TBB, sundials, perftools).

##### Elements
- Core (dark gray)
- Selection (blue), Prediction (green), Fitting (orange), Analysis (purple), Special/PRISM (teal)
- CLI Tools (yellow), Scripts (light gray)
- External Dependencies (side area, red)
- Clear labels: component name, package path, CMake target name.

##### Detailed capture of essential elements
- Don’t try to show every source file—focus on modules.
- Build pipeline: CMake orchestrates library compilation, then executables are linked, then scripts run executables.
- Where external libraries are linked into each component.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Core Layer"
        Core["Core Library"]:::core
    end

    subgraph "Selection Layer"
        Cuts["Cuts Library"]:::selection
        Vars["Vars Library"]:::selection
    end

    subgraph "Prediction Layer"
        Prediction["Prediction Library"]:::prediction
        Extrap["Extrapolation Library"]:::prediction
        Experiment["Experiment Library"]:::prediction
    end

    subgraph "Fitting Layer"
        Fit["Fitting Library"]:::fitting
    end

    subgraph "Analysis Layer"
        Systs["Systematics Library"]:::analysis
        Analysis["Analysis Library"]:::analysis
    end

    subgraph "Special/PRISM Module"
        PRISM["PRISM Module"]:::special
    end

    subgraph "CLI Tools"
        Bin["bin Executables"]:::cli
        Cafe["cafe Executables"]:::cli
    end

    subgraph "Scripts & Orchestration"
        Scripts["Orchestration Scripts"]:::script
        FCL["Config FCL Files"]:::script
    end

    subgraph "External Dependencies"
        BuildCMake["Build & Find Modules"]:::external
    end

    %% Dependencies on Core
    Cuts --> Core
    Vars --> Core
    Prediction --> Core
    Extrap --> Core
    Experiment --> Core
    Fit --> Core
    Systs --> Core
    Analysis --> Core

    %% Inter-layer dependencies
    Cuts --> Analysis
    Vars --> Analysis
    Systs --> Analysis
    Prediction --> Analysis
    Experiment --> Analysis

    Prediction --> Extrap
    Prediction --> Experiment

    Fit --> Systs

    %% Interfaces
    IFitter[(IFitter)]:::interface
    IExtrap[(IExtrap)]:::interface
    IExperiment[(IExperiment)]:::interface

    Fit --> IFitter
    Extrap --> IExtrap
    Experiment --> IExperiment

    PRISM -.-> IFitter
    PRISM -.-> IExtrap
    PRISM -.-> IExperiment
    PRISM --> Analysis
    PRISM --> Prediction
    PRISM --> Experiment
    PRISM --> Systs
    PRISM --> Extrap

    %% CLI and Scripts
    Bin --> Analysis
    Bin --> Prediction
    Bin --> Fit
    Cafe --> Analysis
    Cafe --> Prediction
    Cafe --> Fit

    Scripts --> Bin
    Scripts --> Cafe
    Scripts --> FCL

    %% Build modules link
    Core --> BuildCMake
    Cuts --> BuildCMake
    Vars --> BuildCMake
    Prediction --> BuildCMake
    Extrap --> BuildCMake
    Experiment --> BuildCMake
    Fit --> BuildCMake
    Systs --> BuildCMake
    Analysis --> BuildCMake
    PRISM --> BuildCMake

    %% Click events
    click Core "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Core/"
    click Cuts "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Cuts/"
    click Vars "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Vars/"
    click Systs "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Systs/"
    click Prediction "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Prediction/"
    click Extrap "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Extrap/"
    click Experiment "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Experiment/"
    click Fit "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Fit/"
    click Analysis "https://github.com/dune/lblpwgtools/tree/master/CAFAna/Analysis/"
    click PRISM "https://github.com/dune/lblpwgtools/tree/master/CAFAna/PRISM/"
    click Bin "https://github.com/dune/lblpwgtools/tree/master/CAFAna/bin/"
    click Cafe "https://github.com/dune/lblpwgtools/tree/master/CAFAna/cafe/"
    click BuildCMake "https://github.com/dune/lblpwgtools/tree/master/CAFAna/cmake/"
    click Scripts "https://github.com/dune/lblpwgtools/tree/master/CAFAna/scripts/"
    click FCL "https://github.com/dune/lblpwgtools/tree/master/CAFAna/fcl/"

    %% Styles
    classDef core fill:#555555,stroke:#333,color:#fff;
    classDef selection fill:#88c0d0,stroke:#5e81ac,color:#000;
    classDef prediction fill:#a3be8c,stroke:#4c566a,color:#000;
    classDef fitting fill:#ebcb8b,stroke:#b48ead,color:#000;
    classDef analysis fill:#b48ead,stroke:#5e81ac,color:#fff;
    classDef special fill:#8fbcbb,stroke:#2e3440,color:#000;
    classDef cli fill:#ebcb8b,stroke:#d08770,color:#000;
    classDef script fill:#d8dee9,stroke:#4c566a,color:#000;
    classDef external fill:#bf616a,stroke:#742a2a,color:#fff;
    classDef interface stroke-dasharray: 5 5,shape:diamond,fill:#eceff4,color:#000;
    class IFitter,IExtrap,IExperiment interface
```
