modified: TrackRecon.C

modified:   eloss_calculations/Eloss.py
	new file:   eloss_calculations/deutron_lookup_20MeV_3pc.dat for 27Al(a,d) pathway
	new file:   scratch/plot_dither_scan.C optimising dithering for A1C1 and A1C0 events
	new file:   scratch/scan_dither_runs.sh
	renamed:    scan_slope_runs.sh -> scratch/scan_slope_runs.sh
This commit is contained in:
Vignesh Sitaraman 2026-06-12 10:42:22 -04:00
parent 7861cc496c
commit 1bbf2ae059
6 changed files with 222235 additions and 7 deletions

View File

@ -49,6 +49,7 @@ double source_vertex = 53; // 53
const double qqq_z = 105.0;
double z_entrance = -174.3 - 9.7 - 100.0;
const double anode_gain = 1.5146e-5; // channels --> MeV
double dither_sigma = 8.0;
std::string dataset;
int CO2percent;
bool reactiondata = false;
@ -174,6 +175,15 @@ void TrackRecon::Begin(TTree * /*tree*/)
CO2percent = std::atoi(getenv("CO2percent"));
std::cout << "CO2 percent set to " << CO2percent << std::endl;
if (getenv("source_vertex"))
source_vertex = (double)std::atof(std::string(getenv("source_vertex")).c_str());
if (getenv("DITHER_SIGMA"))
{
dither_sigma = std::atof(getenv("DITHER_SIGMA"));
std::cout << "Dither Sigma set to " << dither_sigma << " mm" << std::endl;
}
pwinstance.ConstructGeo();
for (int i = 0; i < 48; i++)
@ -1542,7 +1552,7 @@ void PCSX3ClusterAnalysis(HistPlotter *plotter, std::vector<Event> QQQ_Events, s
// SX3 hit's phi, with the same quality cuts as miscHistograms_oneWire
auto [apwire_bm, apSumE_bm, apMaxE_bm, apTSMaxE_bm] = pwinstance.GetPseudoWire(aCl, "ANODE");
TVector3 pc_anodeOnly = pwinstance.getClosestWirePosAtWirePhi(apwire_bm, sx3event.pos.Phi());
pc_anodeOnly.SetZ(rand.Gaus(pc_anodeOnly.Z(), 8.0));
pc_anodeOnly.SetZ(rand.Gaus(pc_anodeOnly.Z(), dither_sigma));
TVector3 vtx_anodeOnly = vertexFromPCPoint(pc_anodeOnly);
bool anodeOnlyGood = vtx_anodeOnly.Perp() <= 6.0 && vtx_anodeOnly.Z() >= -173.6 && vtx_anodeOnly.Z() <= 100 && phicut;
@ -1550,7 +1560,7 @@ void PCSX3ClusterAnalysis(HistPlotter *plotter, std::vector<Event> QQQ_Events, s
{
fillSuite("A1C2", pcz_ref, vtx_ref); // baseline with identical binning
double pcz_dith = rand.Gaus(pcevent.pos.Z(), 8.0);
double pcz_dith = rand.Gaus(pcevent.pos.Z(), dither_sigma);
TVector3 vtx_a1c1 = vertexFromPCPoint(TVector3(pcevent.pos.X(), pcevent.pos.Y(), pcz_dith));
fillSuite("A1C1", pcz_dith, vtx_a1c1);
@ -1751,7 +1761,7 @@ void PCQQQClusterAnalysis(HistPlotter *plotter, std::vector<Event> QQQ_Events, s
// QQQ hit's phi, with the same quality cuts as miscHistograms_oneWire
auto [apwire_bm, apSumE_bm, apMaxE_bm, apTSMaxE_bm] = pwinstance.GetPseudoWire(aCl, "ANODE");
TVector3 pc_anodeOnly = pwinstance.getClosestWirePosAtWirePhi(apwire_bm, qqqevent.pos.Phi());
pc_anodeOnly.SetZ(rand.Gaus(pc_anodeOnly.Z(), 8.0));
pc_anodeOnly.SetZ(rand.Gaus(pc_anodeOnly.Z(), dither_sigma));
TVector3 vtx_anodeOnly = vertexFromPCPoint(pc_anodeOnly);
bool anodeOnlyGood = vtx_anodeOnly.Perp() <= 6.0 && vtx_anodeOnly.Z() >= -173.6 && vtx_anodeOnly.Z() <= 100 && phicut;
@ -1766,7 +1776,7 @@ void PCQQQClusterAnalysis(HistPlotter *plotter, std::vector<Event> QQQ_Events, s
if (pcevent.Time1 - qqqevent.Time1 < -150 || pcevent.Time1 - qqqevent.Time1 > 850)
continue;
double pcz_dith = rand.Gaus(pcevent.pos.Z(), 8.0);
double pcz_dith = rand.Gaus(pcevent.pos.Z(), dither_sigma);
TVector3 vtx_a1c1 = vertexFromPCPoint(TVector3(pcevent.pos.X(), pcevent.pos.Y(), pcz_dith));
fillSuite("A1C1", pcz_dith, vtx_a1c1);
@ -2323,7 +2333,6 @@ void protonMiscHistograms(HistPlotter *plotter, std::vector<Event> QQQ_Events, s
Kinematics apkin_a(1.008664916, 4.002603254, 4.002603254, 1.008664916, initial_energy); // m3 is alpha
TF1 pcfix_func("pcfix_func", "pol2", -200, 200);
for (auto qqqevent : QQQ_Events)
{
if (qqqevent.Energy1 < 0.6)

View File

@ -61,6 +61,7 @@ def generate_lookup(z, mass_u, e_start_mev, label):
# Format: generate_lookup(Z, mass_u, E_start_MeV, label)
generate_lookup(1, 1.0078, 20, "proton")
generate_lookup(2, 4.0026, 20, "alpha")
generate_lookup(1, 2.01355, 20, "deutron")
generate_lookup(13,26.9815, 80, "aluminum")
generate_lookup(9,17.0021, 70, "fluorine")
generate_lookup(8,15.9949, 70, "oxygen")

File diff suppressed because it is too large Load Diff

188
scratch/plot_dither_scan.C Normal file
View File

@ -0,0 +1,188 @@
#include <TFile.h>
#include <TH1.h>
#include <TGraphErrors.h>
#include <TGraph.h>
#include <TMultiGraph.h>
#include <TCanvas.h>
#include <TLegend.h>
#include <TLine.h>
#include <TString.h>
#include <TStyle.h>
#include <iostream>
void plot_dither_scan()
{
gStyle->SetOptStat(0);
// =========================================================================
// --- Configuration ---
// =========================================================================
double dithers[] = {0.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0};
const int N_DITHER = sizeof(dithers) / sizeof(dithers[0]);
int runs[] = {12, 18, 19, 20, 21};
const int N_RUNS = sizeof(runs) / sizeof(runs[0]);
int runColors[] = {kBlack, kRed, kBlue, kGreen + 2, kMagenta};
TString runNames[] = {"27Al Run 12", "17F Run 18", "17F Run 19", "17F Run 20", "17F Run 21"};
// Graph arrays
TGraphErrors *g_rms_A1C0[N_RUNS];
TGraphErrors *g_rms_A1C1[N_RUNS];
TGraph *g_kurt_A1C0[N_RUNS];
TGraph *g_kurt_A1C1[N_RUNS];
// Initialize graphs
for (int ir = 0; ir < N_RUNS; ir++)
{
// RMS (Spread) Graphs
g_rms_A1C0[ir] = new TGraphErrors(N_DITHER);
g_rms_A1C0[ir]->SetTitle(runNames[ir]);
g_rms_A1C0[ir]->SetMarkerStyle(20);
g_rms_A1C0[ir]->SetMarkerColor(runColors[ir]);
g_rms_A1C0[ir]->SetLineColor(runColors[ir]);
g_rms_A1C1[ir] = new TGraphErrors(N_DITHER);
g_rms_A1C1[ir]->SetTitle(runNames[ir]);
g_rms_A1C1[ir]->SetMarkerStyle(21);
g_rms_A1C1[ir]->SetMarkerColor(runColors[ir]);
g_rms_A1C1[ir]->SetLineColor(runColors[ir]);
// Kurtosis Graphs
g_kurt_A1C0[ir] = new TGraph(N_DITHER);
g_kurt_A1C0[ir]->SetTitle(runNames[ir]);
g_kurt_A1C0[ir]->SetMarkerStyle(24);
g_kurt_A1C0[ir]->SetMarkerColor(runColors[ir]);
g_kurt_A1C0[ir]->SetLineColor(runColors[ir]);
g_kurt_A1C1[ir] = new TGraph(N_DITHER);
g_kurt_A1C1[ir]->SetTitle(runNames[ir]);
g_kurt_A1C1[ir]->SetMarkerStyle(25);
g_kurt_A1C1[ir]->SetMarkerColor(runColors[ir]);
g_kurt_A1C1[ir]->SetLineColor(runColors[ir]);
}
// =========================================================================
// --- Data Extraction Loop ---
// =========================================================================
for (int ir = 0; ir < N_RUNS; ir++)
{
for (int id = 0; id < N_DITHER; id++)
{
TString fileName = TString::Format("dither_scan/run%03d/dither_%.1f.root", runs[ir], dithers[id]);
TFile *f = TFile::Open(fileName);
if (!f || f->IsZombie()) {
std::cout << "Skipping " << fileName << " (Not found)" << std::endl;
continue;
}
auto fetchStats = [&](const char *tag, TGraphErrors *graph_rms, TGraph *graph_kurt)
{
TH1D *h_sx3 = (TH1D *)f->Get(TString::Format("Benchmark_SX3/Benchmark_SX3_PCZ-sx3pczguess_%s", tag));
TH1D *h_qqq = (TH1D *)f->Get(TString::Format("Benchmark_QQQ/Benchmark_QQQ_PCZ-qqqpczguess_%s", tag));
TH1D *h_combo = nullptr;
if (h_sx3 && h_qqq) {
h_combo = (TH1D *)h_sx3->Clone(TString::Format("combo_%s", tag));
h_combo->Add(h_qqq);
} else if (h_sx3) {
h_combo = (TH1D *)h_sx3->Clone(TString::Format("combo_%s", tag));
} else if (h_qqq) {
h_combo = (TH1D *)h_qqq->Clone(TString::Format("combo_%s", tag));
}
if (h_combo && h_combo->GetEntries() > 50)
{
// Use raw statistical properties instead of a Gaussian fit
double rms = h_combo->GetStdDev();
double rmsErr = h_combo->GetStdDevError();
double kurtosis = h_combo->GetKurtosis(); // < 0 means bifurcated, ~0 means Gaussian
graph_rms->SetPoint(id, dithers[id], rms);
graph_rms->SetPointError(id, 0.0, rmsErr);
graph_kurt->SetPoint(id, dithers[id], kurtosis);
delete h_combo;
}
};
fetchStats("A1C0", g_rms_A1C0[ir], g_kurt_A1C0[ir]);
fetchStats("A1C1", g_rms_A1C1[ir], g_kurt_A1C1[ir]);
f->Close();
delete f;
}
}
// =========================================================================
// --- Plotting ---
// =========================================================================
TCanvas *c1 = new TCanvas("c1", "Dither Optimization", 1400, 1000);
c1->Divide(2, 2);
// -- Pad 1: A1C0 RMS
c1->cd(1);
gPad->SetGrid(1, 1);
TMultiGraph *mg_A1C0_rms = new TMultiGraph();
mg_A1C0_rms->SetTitle("A1C0 Emulation Resolution; Dither Sigma (mm); Raw RMS Spread (mm)");
TLegend *leg0 = new TLegend(0.15, 0.65, 0.45, 0.85);
leg0->SetBorderSize(1);
for (int ir = 0; ir < N_RUNS; ir++) {
if (g_rms_A1C0[ir]->GetN() > 0) {
mg_A1C0_rms->Add(g_rms_A1C0[ir], "PL");
leg0->AddEntry(g_rms_A1C0[ir], runNames[ir], "pl");
}
}
mg_A1C0_rms->Draw("A");
leg0->Draw();
// -- Pad 2: A1C1 RMS
c1->cd(2);
gPad->SetGrid(1, 1);
TMultiGraph *mg_A1C1_rms = new TMultiGraph();
mg_A1C1_rms->SetTitle("A1C1 Emulation Resolution; Dither Sigma (mm); Raw RMS Spread (mm)");
TLegend *leg1 = new TLegend(0.15, 0.65, 0.45, 0.85);
leg1->SetBorderSize(1);
for (int ir = 0; ir < N_RUNS; ir++) {
if (g_rms_A1C1[ir]->GetN() > 0) {
mg_A1C1_rms->Add(g_rms_A1C1[ir], "PL");
leg1->AddEntry(g_rms_A1C1[ir], runNames[ir], "pl");
}
}
mg_A1C1_rms->Draw("A");
leg1->Draw();
// -- Pad 3: A1C0 Kurtosis
c1->cd(3);
gPad->SetGrid(1, 1);
TMultiGraph *mg_A1C0_kurt = new TMultiGraph();
mg_A1C0_kurt->SetTitle("A1C0 Bifurcation Metric; Dither Sigma (mm); Excess Kurtosis (0 = Gaussian)");
for (int ir = 0; ir < N_RUNS; ir++) {
if (g_kurt_A1C0[ir]->GetN() > 0) mg_A1C0_kurt->Add(g_kurt_A1C0[ir], "PL");
}
mg_A1C0_kurt->Draw("A");
// Draw a horizontal line at y=0 to easily spot where it becomes Gaussian
c1->Update();
TLine *line0 = new TLine(c1->cd(3)->GetUxmin(), 0, c1->cd(3)->GetUxmax(), 0);
line0->SetLineColor(kBlack); line0->SetLineStyle(2); line0->SetLineWidth(2);
line0->Draw();
// -- Pad 4: A1C1 Kurtosis
c1->cd(4);
gPad->SetGrid(1, 1);
TMultiGraph *mg_A1C1_kurt = new TMultiGraph();
mg_A1C1_kurt->SetTitle("A1C1 Bifurcation Metric; Dither Sigma (mm); Excess Kurtosis (0 = Gaussian)");
for (int ir = 0; ir < N_RUNS; ir++) {
if (g_kurt_A1C1[ir]->GetN() > 0) mg_A1C1_kurt->Add(g_kurt_A1C1[ir], "PL");
}
mg_A1C1_kurt->Draw("A");
c1->Update();
TLine *line1 = new TLine(c1->cd(4)->GetUxmin(), 0, c1->cd(4)->GetUxmax(), 0);
line1->SetLineColor(kBlack); line1->SetLineStyle(2); line1->SetLineWidth(2);
line1->Draw();
c1->SaveAs("dither_optimization_results.png");
}

View File

@ -0,0 +1,53 @@
#!/bin/bash
# Scans dither_sigma from 0.0 to 10.0 mm.
# No recompilation needed per step; values are passed via environment variable!
set -e
SCAN_DIR="dither_scan"
echo "=== Compiling TrackRecon.C once... ==="
root -q -l -b -e '.L TrackRecon.C++O' 2>/dev/null
process_run() {
local wrun=$(printf "%03d" "$1")
local dither="$2"
local outdir="${SCAN_DIR}/run${wrun}"
mkdir -p "$outdir"
local out="${outdir}/dither_${dither}.root"
# Pass the variable to C++
export DITHER_SIGMA="$dither"
root -q -l -b -x "../../ANASEN_analysis/data/${DATASET}_Data/${PREFIX}${wrun}_mapped.root" \
-e "tree->Process(\"TrackRecon.C+\", \"${out}\")" > /dev/null 2>&1
[ -f "$out" ] && echo " run $wrun dither $dither OK" || echo " run $wrun dither $dither FAILED"
}
export -f process_run
export SCAN_DIR
# Loop through the dither amounts (in mm) you want to test
for dither in 0.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0; do
echo "=== Scanning Dither Sigma = ${dither} mm ==="
# 27Al alpha+gas runs (9, 12)
export DATASET="27Al" PREFIX="Run_"
echo " 27Al runs 9 12..."
# FIX: Changed "$slope" to "$dither"
export source_vertex=53.44; export timecut_low=400.0; process_run 12 "$dither"
export source_vertex=-5.36; export timecut_low=12.0; export timecut_high=120.0; process_run 9 "$dither"
unset timecut_low
unset timecut_high
# 17F alpha runs with per-run source vertices
export DATASET="17F" PREFIX="SourceRun_"
echo " 17F runs 18-21..."
export source_vertex=53.44; process_run 18 "$dither"
export source_vertex=14.24; process_run 19 "$dither"
export source_vertex=-24.96; process_run 20 "$dither"
export source_vertex=-73.96; process_run 21 "$dither"
done
echo "=== Dither scan complete! ==="

View File

@ -4,7 +4,7 @@
# runs all source runs, saves results under slope_scan/run<NNN>/slope_<val>.root
set -e
CORRECTION_H="Armory/PC_StepLadder_Correction.h"
CORRECTION_H="../Armory/PC_StepLadder_Correction.h"
SCAN_DIR="slope_scan"
process_run() {
@ -13,7 +13,7 @@ process_run() {
local outdir="${SCAN_DIR}/run${wrun}"
mkdir -p "$outdir"
local out="${outdir}/slope_${slope}.root"
root -q -l -b -x "../ANASEN_analysis/data/${DATASET}_Data/${PREFIX}${wrun}_mapped.root" \
root -q -l -b -x "../../ANASEN_analysis/data/${DATASET}_Data/${PREFIX}${wrun}_mapped.root" \
-e "tree->Process(\"TrackRecon.C+\", \"${out}\")" > /dev/null 2>&1
[ -f "$out" ] && echo " run $wrun slope $slope OK" || echo " run $wrun slope $slope FAILED"
}