# provakar1994/bbcal_calibration architecture

> Architecture diagram of the GitHub repository provakar1994/bbcal_calibration, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/provakar1994/bbcal_calibration
- Repository: https://github.com/provakar1994/bbcal_calibration

## Overview

This repository is a collection of ROOT macros for older BigBite Calorimeter cosmic calibration and related gain/HV tuning. The main workflow analyzes replayed detector data to estimate channel peaks, then uses those measurements with HV settings to derive and export adjustments. Separate macros cover shower/preshower cosmic analysis, beam-energy gain calibration, and trigger-to-FADC amplitude targeting. Excerpts show key file reads and calculations, but not every macro’s complete input/output wiring.

Main entry points: [`PreShower_HV_Peak.C`](https://github.com/provakar1994/bbcal_calibration/blob/master/PreShower_HV_Peak.C) (Preshower peak analysis), [`HV_Peak.C`](https://github.com/provakar1994/bbcal_calibration/blob/master/HV_Peak.C) (Shower HV peak analysis), [`HV_Peak_v2.C`](https://github.com/provakar1994/bbcal_calibration/blob/master/HV_Peak_v2.C) (Shower HV analysis v2), [`Sh_hv_tweak.C`](https://github.com/provakar1994/bbcal_calibration/blob/master/Sh_hv_tweak.C) (Shower HV adjustment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cosmic["Cosmic analysis"]
  node_shower_cos["Shower cosmic analysis<br/>[bbcal_cos_cal.C]"]
  node_sh_cos["Shower cosmic variant<br/>[bbsh_cos_cal.C]"]
  node_ps_cos["Preshower cosmic analysis<br/>[bbps_cos_cal.C]"]
  node_fadc_header["FADC data arrays<br/>[fadc_data.h]"]
end

subgraph group_hv["HV calibration"]
  node_prepeak["Preshower peak analysis"]
  node_hvpeak["Shower HV peak analysis<br/>[HV_Peak.C]"]
  node_hvpeak2["Shower HV analysis v2<br/>[HV_Peak_v2.C]"]
  node_hvtweak["Shower HV adjustment<br/>[Sh_hv_tweak.C]"]
end

subgraph group_energy["Energy calibration"]
  node_engcal["Beam energy calibration<br/>[eng_cal_BBCal.C]"]
end

subgraph group_fadc["FADC targeting"]
  node_targetamp["Preshower amplitude targets<br/>[targetFADCamp.C]"]
end

node_operator(("Calibration operator"))
node_replay["Replayed ROOT data"]
node_peakfiles["Peak measurements"]
node_hvsettings["HV settings"]
node_gainfiles["Gain coefficients"]
node_alphas["Shower alpha values"]
node_histfiles["Shower histogram ROOT"]
node_trigcoeff["Trigger/FADC coefficients"]
node_pscoeff["Preshower trigger coefficients"]
node_hvoutput["Updated HV settings"]
node_gainoutput["Gain coefficient output"]
node_ampoutput["Target amplitude output"]
node_plots["Calibration plots"]

node_operator -->|"runs"| node_shower_cos
node_operator -->|"runs"| node_sh_cos
node_operator -->|"runs"| node_ps_cos
node_operator -->|"runs"| node_hvpeak
node_operator -->|"runs"| node_hvpeak2
node_operator -->|"runs"| node_prepeak
node_operator -->|"runs"| node_hvtweak
node_operator -->|"runs"| node_engcal
node_operator -->|"runs"| node_targetamp
node_shower_cos -->|"reads"| node_replay
node_sh_cos -->|"reads"| node_replay
node_ps_cos -->|"reads"| node_replay
node_engcal -->|"reads"| node_replay
node_shower_cos -->|"uses data arrays"| node_fadc_header
node_ps_cos -->|"uses data arrays"| node_fadc_header
node_shower_cos -->|"writes peaks"| node_peakfiles
node_ps_cos -->|"writes peaks"| node_peakfiles
node_hvpeak -->|"reads peaks"| node_peakfiles
node_hvpeak2 -->|"reads peaks"| node_peakfiles
node_prepeak -->|"reads peaks"| node_peakfiles
node_hvpeak -->|"reads settings"| node_hvsettings
node_hvpeak2 -->|"reads settings"| node_hvsettings
node_prepeak -->|"reads settings"| node_hvsettings
node_hvpeak -->|"writes adjustments"| node_hvoutput
node_hvpeak2 -->|"writes adjustments"| node_hvoutput
node_prepeak -->|"writes adjustments"| node_hvoutput
node_hvtweak -->|"reads settings"| node_hvsettings
node_hvtweak -.->|"reads coefficients"| node_alphas
node_hvtweak -.->|"reads gains"| node_gainfiles
node_hvtweak -->|"writes adjustments"| node_hvoutput
node_engcal -->|"reads prior gains"| node_gainfiles
node_engcal -->|"writes gains"| node_gainoutput
node_hvpeak -->|"reads histograms"| node_histfiles
node_hvpeak2 -->|"reads histograms"| node_histfiles
node_prepeak -->|"reads histograms"| node_histfiles
node_targetamp -->|"reads coefficients"| node_pscoeff
node_targetamp -->|"writes targets"| node_ampoutput
node_targetamp -->|"saves plot"| node_plots
node_hvpeak -->|"saves plots"| node_plots
node_hvpeak2 -->|"saves plots"| node_plots
node_prepeak -->|"saves plots"| node_plots

click node_shower_cos "https://github.com/provakar1994/bbcal_calibration/blob/master/bbcal_cos_cal.C"
click node_sh_cos "https://github.com/provakar1994/bbcal_calibration/blob/master/bbsh_cos_cal.C"
click node_ps_cos "https://github.com/provakar1994/bbcal_calibration/blob/master/bbps_cos_cal.C"
click node_prepeak "https://github.com/provakar1994/bbcal_calibration/blob/master/PreShower_HV_Peak.C"
click node_hvpeak "https://github.com/provakar1994/bbcal_calibration/blob/master/HV_Peak.C"
click node_hvpeak2 "https://github.com/provakar1994/bbcal_calibration/blob/master/HV_Peak_v2.C"
click node_hvtweak "https://github.com/provakar1994/bbcal_calibration/blob/master/Sh_hv_tweak.C"
click node_engcal "https://github.com/provakar1994/bbcal_calibration/blob/master/eng_cal_BBCal.C"
click node_targetamp "https://github.com/provakar1994/bbcal_calibration/blob/master/targetFADCamp.C"
click node_peakfiles "https://github.com/provakar1994/bbcal_calibration/tree/master/Output"
click node_hvsettings "https://github.com/provakar1994/bbcal_calibration/tree/master/hv_set"
click node_trigcoeff "https://github.com/provakar1994/bbcal_calibration/blob/master/trigtoFADCcoef_SH.txt"
click node_pscoeff "https://github.com/provakar1994/bbcal_calibration/blob/master/trigtoFADCcoef_PS.txt"
click node_hvoutput "https://github.com/provakar1994/bbcal_calibration/tree/master/hv_set"
click node_ampoutput "https://github.com/provakar1994/bbcal_calibration/tree/master/Output"
click node_plots "https://github.com/provakar1994/bbcal_calibration/tree/master/plots"
click node_fadc_header "https://github.com/provakar1994/bbcal_calibration/blob/master/fadc_data.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_shower_cos,node_sh_cos,node_ps_cos,node_fadc_header toneBlue
class node_prepeak,node_hvpeak,node_hvpeak2,node_hvtweak toneAmber
class node_engcal toneMint
class node_targetamp toneRose
class node_operator,node_replay,node_gainfiles,node_alphas,node_histfiles,node_gainoutput toneIndigo
class node_peakfiles,node_hvsettings,node_trigcoeff,node_pscoeff,node_hvoutput,node_ampoutput,node_plots toneTeal
```

## Components

### Cosmic analysis

- [Shower cosmic analysis](https://github.com/provakar1994/bbcal_calibration/blob/master/bbcal_cos_cal.C): `bbcal_cos_cal.C`
- [Shower cosmic variant](https://github.com/provakar1994/bbcal_calibration/blob/master/bbsh_cos_cal.C): `bbsh_cos_cal.C`
- [Preshower cosmic analysis](https://github.com/provakar1994/bbcal_calibration/blob/master/bbps_cos_cal.C): `bbps_cos_cal.C`
- [FADC data arrays](https://github.com/provakar1994/bbcal_calibration/blob/master/fadc_data.h): `fadc_data.h`

### HV calibration

- [Preshower peak analysis](https://github.com/provakar1994/bbcal_calibration/blob/master/PreShower_HV_Peak.C): `PreShower_HV_Peak.C`
- [Shower HV peak analysis](https://github.com/provakar1994/bbcal_calibration/blob/master/HV_Peak.C): `HV_Peak.C`
- [Shower HV analysis v2](https://github.com/provakar1994/bbcal_calibration/blob/master/HV_Peak_v2.C): `HV_Peak_v2.C`
- [Shower HV adjustment](https://github.com/provakar1994/bbcal_calibration/blob/master/Sh_hv_tweak.C): `Sh_hv_tweak.C`

### Energy calibration

- [Beam energy calibration](https://github.com/provakar1994/bbcal_calibration/blob/master/eng_cal_BBCal.C): `eng_cal_BBCal.C`

### FADC targeting

- [Preshower amplitude targets](https://github.com/provakar1994/bbcal_calibration/blob/master/targetFADCamp.C): `targetFADCamp.C`

### Other components

- **Calibration operator**
- **Replayed ROOT data**
- [Peak measurements](https://github.com/provakar1994/bbcal_calibration/tree/master/Output): `Output`
- [HV settings](https://github.com/provakar1994/bbcal_calibration/tree/master/hv_set): `hv_set`
- **Gain coefficients**
- **Shower alpha values**
- **Shower histogram ROOT**
- [Trigger/FADC coefficients](https://github.com/provakar1994/bbcal_calibration/blob/master/trigtoFADCcoef_SH.txt): `trigtoFADCcoef_SH.txt`
- [Preshower trigger coefficients](https://github.com/provakar1994/bbcal_calibration/blob/master/trigtoFADCcoef_PS.txt): `trigtoFADCcoef_PS.txt`
- [Updated HV settings](https://github.com/provakar1994/bbcal_calibration/tree/master/hv_set): `hv_set`
- **Gain coefficient output**
- [Target amplitude output](https://github.com/provakar1994/bbcal_calibration/tree/master/Output): `Output`
- [Calibration plots](https://github.com/provakar1994/bbcal_calibration/tree/master/plots): `plots`

## Connections

- Calibration operator → Shower cosmic analysis: runs
- Calibration operator → Shower cosmic variant: runs
- Calibration operator → Preshower cosmic analysis: runs
- Calibration operator → Shower HV peak analysis: runs
- Calibration operator → Shower HV analysis v2: runs
- Calibration operator → Preshower peak analysis: runs
- Calibration operator → Shower HV adjustment: runs
- Calibration operator → Beam energy calibration: runs
- Calibration operator → Preshower amplitude targets: runs
- Shower cosmic analysis → Replayed ROOT data: reads
- Shower cosmic variant → Replayed ROOT data: reads
- Preshower cosmic analysis → Replayed ROOT data: reads
- Beam energy calibration → Replayed ROOT data: reads
- Shower cosmic analysis → FADC data arrays: uses data arrays
- Preshower cosmic analysis → FADC data arrays: uses data arrays
- Shower cosmic analysis → Peak measurements: writes peaks
- Preshower cosmic analysis → Peak measurements: writes peaks
- Shower HV peak analysis → Peak measurements: reads peaks
- Shower HV analysis v2 → Peak measurements: reads peaks
- Preshower peak analysis → Peak measurements: reads peaks
- Shower HV peak analysis → HV settings: reads settings
- Shower HV analysis v2 → HV settings: reads settings
- Preshower peak analysis → HV settings: reads settings
- Shower HV peak analysis → Updated HV settings: writes adjustments
- Shower HV analysis v2 → Updated HV settings: writes adjustments
- Preshower peak analysis → Updated HV settings: writes adjustments
- Shower HV adjustment → HV settings: reads settings
- Shower HV adjustment → Shower alpha values: reads coefficients
- Shower HV adjustment → Gain coefficients: reads gains
- Shower HV adjustment → Updated HV settings: writes adjustments
- Beam energy calibration → Gain coefficients: reads prior gains
- Beam energy calibration → Gain coefficient output: writes gains
- Shower HV peak analysis → Shower histogram ROOT: reads histograms
- Shower HV analysis v2 → Shower histogram ROOT: reads histograms
- Preshower peak analysis → Shower histogram ROOT: reads histograms
- Preshower amplitude targets → Preshower trigger coefficients: reads coefficients
- Preshower amplitude targets → Target amplitude output: writes targets
- Preshower amplitude targets → Calibration plots: saves plot
- Shower HV peak analysis → Calibration plots: saves plots
- Shower HV analysis v2 → Calibration plots: saves plots
- Preshower peak analysis → Calibration plots: saves plots
