# π⁺π⁻ Invariant Mass Explorer — AI-Assisted Physics Workshop

## Overview

In this workshop, you will build an interactive physics data exploration tool using Python, Tkinter, and matplotlib, guided step-by-step by AI-generated prompts.

The goal is not to manually write everything from scratch, but to learn how to:
- Work with real experimental physics data
- Use GitHub Copilot effectively during development
- Build a fully interactive GUI step by step
- Understand how complex systems can be constructed incrementally

---

## Workshop Setup Instructions

Go to the folder inside `/w` that was assigned to your group/hall and create a new directory for this workshop. Once you are inside that directory on ifarm, copy the dataset using:

```bash
cp /w/epsci-scshelf2103/rasool/handsOnWorkshop/events.json .
```

This dataset contains real experimental physics data that was converted from `.root` format into `.json` format to simplify the workflow for the workshop.

---

## Before You Begin


The prompts below may look extremely detailed or technical. That does **not** mean you are expected to fully understand every implementation detail before starting.

The prompts were intentionally written to be highly specific because many participants will be using the free version of GitHub Copilot, which often relies on smaller models such as Haiku. Smaller models can drift away from requirements unless instructions are very explicit. This is also one of the reasons why the workshop data was converted from `.root` into `.json`.

When we built the same project using stronger coding models such as Sonnet 4.6, much shorter and more general prompts were enough because those models could infer many implementation details automatically.

The important takeaway is:

* You do **not** need to know every technical detail ahead of time.
* Use ChatGPT, Claude, Copilot Chat, or similar tools as brainstorming partners.
* Use planning/ask mode to discuss approaches before diving into building.
* Let the AI help you determine the best languages, framework, packages etc. based on your goals and available resources.
* Once you are satisfied with the plan, ask the model to generate more refined implementation prompts for the actual coding phase.

**With stronger models, you will probably not need prompts this detailed.**

---

## Expected Workflow

For each prompt:

1. Paste the prompt into AI chat interface.
2. Allow any commands it suggests (if safe and expected)
4. Run the application:

   ```bash
   python main.py
   ```
5. Observe changes in the GUI

---

## Important Rules

* The application does **not auto-refresh**
* You must **quit (Ctrl + C) and then restart the app** after each prompt completion to see the changes.
* Do **not manually refactor or redesign the code** unless explicitly instructed
* Follow prompts incrementally — do not skip ahead
* If something breaks, that is expected during development, ask AI to fix it. If confuse, ask instructors for help.

---

# Prompt 1 — Base GUI

```text
Create a single-file Python desktop application called main.py using Tkinter and matplotlib.

Requirements:
- Window size 1400x850
- Dark theme
- Left panel for controls
- Right panel for plots
- Embed matplotlib using FigureCanvasTkAgg
- Add a placeholder histogram
- Title:
  "π⁺π⁻ Invariant Mass Explorer"

Use only:
- tkinter
- json
- math
- numpy
- matplotlib

Do not use pandas, scipy, or external GUI frameworks.
Keep all code in one file.
```

---

# Prompt 2 — Load Real JSON Data

```text
Now load real data from events.json at startup.

The JSON file contains a list of dictionaries with fields including:
- pippim_mass
- beam_E
- ChiSq_KinFit
- NumUnusedShowers
- IsComboCut

Requirements:
- Use Python json module only
- Store loaded data in a variable called events
- Print total loaded event count
- Plot histogram using pippim_mass values
- Use 100 bins
- Histogram x-axis range: 0.4 to 1.4 GeV

Do not redesign the GUI.
Keep all code in one file.
```

---

# Debug Prompt (Optional)

```text
Make the left control panel scrollable using Tkinter canvas/scrollbar so all controls are accessible. Do not redesign the application layout.
```

---

# Prompt 3 — Add Cut Controls

```text
Add cut controls in the left panel.

Add:
- ChiSq_KinFit maximum slider
- NumUnusedShowers maximum slider
- Beam energy minimum slider
- Beam energy maximum slider
- IsComboCut checkbox

Requirements:
- When a control changes, update histogram
- Apply cuts to the loaded events list
- Use Tkinter Scale widgets
- Show current slider values beside sliders

Do not redesign the application.
Do not add classes.
Keep everything in one file.
```

---

# Prompt 4 — Add Timing Cuts

```text
Add timing chi-squared cut sliders.

Add:
- PiPlus timing max
- PiMinus timing max
- Proton timing max

Use fields:
- PiPlus__ChiSq_Timing_KinFit
- PiMinus__ChiSq_Timing_KinFit
- Proton__ChiSq_Timing_KinFit

Requirements:
- Update histogram when sliders change
- Keep existing layout
- Do not rewrite filtering logic
```

---

# Prompt 5 — Add Resonance Markers

```text
Add vertical dashed resonance reference lines:

- rho(770) at 0.7755
- omega(782) at 0.78265
- f0(980) at 0.980
- f2(1270) at 1.275

Requirements:
- Add small labels near top
- Keep lines semi-transparent
- Do not modify filtering logic
```

---

# Prompt 6 — Add Physics Overlay Curves

```text
Add smooth overlay curves on histogram using numpy only:

- broad rho-like peak
- narrow omega-like peak
- smooth exponential background

Requirements:
- No fitting libraries
- Add legend
- Keep visual (not physically fitted)
- Do not redesign application
```

---

# Prompt 7 — Add Statistics Panel

```text
Add statistics panel below controls:

Show:
- total events
- filtered events
- fraction passing cuts
- mean invariant mass
- beam energy range

Update automatically when cuts change.

Keep dark theme styling.
```

---

# Prompt 8 — Add Pull Plot

```text
Add pull plot below histogram:

- pull = (data - model) / sqrt(data)
- use overlay curves as model
- shared x-axis
- highlight |pull| > 2 in red

Do not change layout.
```

---

# Prompt 9 — Add Notebook Tabs

```text
Add Tkinter notebook with two tabs:

Tab 1:
- invariant mass histogram
- pull plot

Tab 2:
- beam energy histogram
- ChiSq_KinFit histogram

Cuts should update all plots.
```

---

# Prompt 10 — Add Save Plot Button

```text
Add "Save Plot" button:

- opens folder picker
- saves PNG
- includes timestamp
- use only standard libraries

Do not redesign application.
```

---

## End of Workshop

You now have a fully interactive physics visualization tool built incrementally using AI-assisted development.
