modified: .vscode/c_cpp_properties.json made changes to include the laptop

modified:   GainMatchSX3.C included flags to allow interactive mode and verbose fit
	modified:   GainMatchSX3Front.C included flags to allow interactive mode and verbose fit
This commit is contained in:
Vignesh Sitaraman 2025-07-31 12:07:07 -04:00
parent 3d0d176f5a
commit b44ffd7fdf
3 changed files with 98 additions and 54 deletions

View File

@ -66,6 +66,18 @@
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
},
{
"name": "VigneshROG",
"includePath": [
"${workspaceFolder}/**",
"/home/vsitaraman/root/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4

View File

@ -38,6 +38,11 @@ const int MAX_BK = 4;
double frontGain[MAX_DET][MAX_BK][MAX_UP][MAX_DOWN] = {{{{0}}}};
bool frontGainValid[MAX_DET][MAX_BK][MAX_UP][MAX_DOWN] = {{{{false}}}};
// ==== Configuration Flags ====
const bool interactiveMode = false; // If true: show canvas + wait for user
const bool verboseFit = true; // If true: print fit summary and chi²
const bool drawCanvases = true; // If false: canvases won't be drawn at all
void GainMatchSX3::Begin(TTree * /*tree*/)
{
TString option = GetOption();
@ -240,7 +245,7 @@ Bool_t GainMatchSX3::Process(Long64_t entry)
hist2d->Fill(sx3EUp + sx3EDn, sx3EBk);
if (cut && cut->IsInside(sx3EUp + sx3EDn, sx3EBk))// && cut1 && cut1->IsInside(sx3EUp / sx3EBk, sx3EDn / sx3EBk))
// if (cut && cut->IsInside(sx3EUp + sx3EDn, sx3EBk))// && cut1 && cut1->IsInside(sx3EUp / sx3EBk, sx3EDn / sx3EBk))
{
// Accumulate data for gain matching
// if (frontGainValid[sx3.id[i]][sx3ChBk][sx3ChUp][sx3ChDn])
@ -337,17 +342,20 @@ void GainMatchSX3::Terminate()
TGraphErrors g(xVals.size(), xVals.data(), yVals.data(), exVals.data(), eyVals.data());
TF1 f("f", "[0]*x", 0, 16000);
// f.SetParameter(0, 1.0); // Initial guess
f.SetParameter(0, 1.0); // Initial guess
// Interactive canvas
if (drawCanvases)
{
TCanvas *c = new TCanvas(Form("c_%d_%d_%d_%d", id, bk, u, d), "Fit", 800, 600);
g.SetTitle(Form("Detector %d: U%d D%d B%d", id, u, d, bk));
g.SetMarkerStyle(20);
g.SetMarkerColor(kBlue);
g.Draw("AP");
g.Fit(&f, "Q"); // Quiet fit
g.Fit(&f, interactiveMode ? "Q" : "QNR"); // 'R' avoids refit, 'N' skips drawing
if (verboseFit)
{
double chi2 = f.GetChisquare();
int ndf = f.GetNDF();
double reducedChi2 = (ndf != 0) ? chi2 / ndf : -1;
@ -355,15 +363,21 @@ void GainMatchSX3::Terminate()
std::cout << Form("Det%d U%d D%d B%d → Gain: %.4f | χ²/ndf = %.2f/%d = %.2f",
id, u, d, bk, f.GetParameter(0), chi2, ndf, reducedChi2)
<< std::endl;
}
// Show canvas and wait for user to continue
if (interactiveMode)
{
c->Update();
gPad->WaitPrimitive();
if (TMath::Abs(f.GetParameter(0) - 1) > 3.0)
}
else
{
delete c; // Clean up unused canvas
continue;
c->Close(); // Optionally avoid clutter in batch
}
}
else
{
g.Fit(&f, "QNR");
}
gainArray[id][bk][u][d] = f.GetParameter(0);

View File

@ -42,6 +42,11 @@ bool backGainValid[MAX_DET][MAX_BK][MAX_UP][MAX_DOWN] = {{{{false}}}};
double frontGain[MAX_DET][MAX_BK][MAX_UP][MAX_DOWN] = {{{{0}}}};
bool frontGainValid[MAX_DET][MAX_BK][MAX_UP][MAX_DOWN] = {{{{false}}}};
// ==== Configuration Flags ====
const bool interactiveMode = false; // If true: show canvas + wait for user
const bool verboseFit = true; // If true: print fit summary and chi²
const bool drawCanvases = true; // If false: canvases won't be drawn at all
void GainMatchSX3Front::Begin(TTree * /*tree*/)
{
TString option = GetOption();
@ -223,8 +228,7 @@ Bool_t GainMatchSX3Front::Process(Long64_t entry)
hist2d->Fill(sx3EUp + sx3EDn, sx3EBk);
if (cut && cut->IsInside(sx3EUp + sx3EDn, sx3EBk)
&& cut1 && cut1->IsInside(sx3EUp / sx3EBk, sx3EDn / sx3EBk))
if (cut && cut->IsInside(sx3EUp + sx3EDn, sx3EBk) && cut1 && cut1->IsInside(sx3EUp / sx3EBk, sx3EDn / sx3EBk))
{
if (backGainValid[sx3.id[i]][sx3ChBk][sx3ChUp][sx3ChDn])
@ -308,17 +312,20 @@ void GainMatchSX3Front::Terminate()
TGraphErrors g(xVals.size(), xVals.data(), yVals.data(), exVals.data(), eyVals.data());
TF1 f("f", "[0]*x", 0, 16000);
// f.SetParameter(0, 1.0); // Initial guess
f.SetParameter(0, 1.0); // Initial guess
// Interactive canvas
if (drawCanvases)
{
TCanvas *c = new TCanvas(Form("c_%d_%d_%d_%d", id, bk, u, d), "Fit", 800, 600);
g.SetTitle(Form("Detector %d: U%d D%d B%d", id, u, d, bk));
g.SetMarkerStyle(20);
g.SetMarkerColor(kBlue);
g.Draw("AP");
g.Fit(&f, "Q"); // Quiet fit
g.Fit(&f, interactiveMode ? "Q" : "QNR"); // 'R' avoids refit, 'N' skips drawing
if (verboseFit)
{
double chi2 = f.GetChisquare();
int ndf = f.GetNDF();
double reducedChi2 = (ndf != 0) ? chi2 / ndf : -1;
@ -326,11 +333,22 @@ void GainMatchSX3Front::Terminate()
std::cout << Form("Det%d U%d D%d B%d → Gain: %.4f | χ²/ndf = %.2f/%d = %.2f",
id, u, d, bk, f.GetParameter(0), chi2, ndf, reducedChi2)
<< std::endl;
}
// Show canvas and wait for user to continue
if (interactiveMode)
{
c->Update();
gPad->WaitPrimitive();
}
else
{
c->Close(); // Optionally avoid clutter in batch
}
}
else
{
g.Fit(&f, "QNR");
}
frontGain[id][bk][u][d] = f.GetParameter(0);
frontGainValid[id][bk][u][d] = true;