modified: GainMatchSX3.C

This commit is contained in:
Vignesh Sitaraman 2025-05-13 13:32:22 -04:00
parent d4582d80ff
commit 9cadfdd191

View File

@ -17,12 +17,12 @@
TH2F *hSX3FvsB; TH2F *hSX3FvsB;
TH2F *hQQQFVB; TH2F *hQQQFVB;
int padID = 0; int padID = 0;
SX3 sx3_contr; SX3 sx3_contr;
TCutG *cut; TCutG *cut;
std::map<std::tuple<int, int, int>, std::vector<std::pair<double, double>>> dataPoints; std::map<std::tuple<int, int, int>, std::vector<std::tuple<double, double, double>>> dataPoints;
void GainMatchSX3::Begin(TTree * /*tree*/) void GainMatchSX3::Begin(TTree * /*tree*/)
{ {
@ -46,6 +46,7 @@ void GainMatchSX3::Begin(TTree * /*tree*/)
return; return;
} }
cut->SetName("sx3cut"); // Ensure the cut has the correct name cut->SetName("sx3cut"); // Ensure the cut has the correct name
} }
Bool_t GainMatchSX3::Process(Long64_t entry) Bool_t GainMatchSX3::Process(Long64_t entry)
@ -148,7 +149,7 @@ Bool_t GainMatchSX3::Process(Long64_t entry)
if (cut && cut->IsInside(sx3EUp + sx3EDn, sx3EBk)) if (cut && cut->IsInside(sx3EUp + sx3EDn, sx3EBk))
{ {
// Accumulate data for gain matching // Accumulate data for gain matching
dataPoints[{sx3.id[i], sx3ChUp, sx3ChBk}].emplace_back(sx3EBk, sx3EUp + sx3EDn); dataPoints[{sx3.id[i], sx3ChUp, sx3ChBk}].emplace_back(sx3EBk, sx3EUp , sx3EDn);
} }
} }
} }
@ -156,7 +157,6 @@ Bool_t GainMatchSX3::Process(Long64_t entry)
return kTRUE; return kTRUE;
} }
void GainMatchSX3::Terminate() void GainMatchSX3::Terminate()
{ {
const int MAX_DET = 24; const int MAX_DET = 24;
@ -174,6 +174,10 @@ void GainMatchSX3::Terminate()
return; return;
} }
// === Updated dataPoints type ===
// std::map<std::tuple<int, int, int>, std::vector<std::tuple<double, double, double>>> dataPoints;
// Gain fit using up+dn vs bk
for (const auto &kv : dataPoints) for (const auto &kv : dataPoints)
{ {
auto [id, ud, bk] = kv.first; auto [id, ud, bk] = kv.first;
@ -184,8 +188,10 @@ void GainMatchSX3::Terminate()
std::vector<double> bkE, udE; std::vector<double> bkE, udE;
for (const auto &pr : pts) for (const auto &pr : pts)
{ {
bkE.push_back(pr.first); double eUp, eDn, eBk;
udE.push_back(pr.second); std::tie(eBk, eUp, eDn) = pr;
bkE.push_back(eBk);
udE.push_back(eUp + eDn);
} }
TGraph g(bkE.size(), bkE.data(), udE.data()); TGraph g(bkE.size(), bkE.data(), udE.data());
@ -195,6 +201,7 @@ void GainMatchSX3::Terminate()
gainValid[id][ud][bk] = true; gainValid[id][ud][bk] = true;
} }
// Output results
for (int id = 0; id < MAX_DET; ++id) for (int id = 0; id < MAX_DET; ++id)
{ {
for (int bk = 0; bk < MAX_BK; ++bk) for (int bk = 0; bk < MAX_BK; ++bk)
@ -213,23 +220,39 @@ void GainMatchSX3::Terminate()
outFile.close(); outFile.close();
std::cout << "Gain matching complete." << std::endl; std::cout << "Gain matching complete." << std::endl;
// === Plot all gain-matched QQQ points together with a 2D histogram === // === Create histograms ===
TH2F *hAll = new TH2F("hAll", "All SX3 Gain-Matched;Corrected Back E;Up+dn E", TH2F *hFVB = new TH2F("hFVB", "Corrected Up+Dn vs Corrected Back;Corrected Back E;Up+Dn E",
400, 0, 16000, 400, 0, 16000); 400, 0, 16000, 400, 0, 16000);
TH2F *hAsym = new TH2F("hAsym", "Up vs Dn dvide back;Up+Dn E;(Up-Dn)/(Up+Dn)",
400, -1.0,1.0, 400, -1.0, 1.0);
// Fill the combined TH2F with corrected data // Fill histograms
for (auto &kv : dataPoints) for (const auto &kv : dataPoints)
{ {
int id, ud, bk; auto [id, ud, bk] = kv.first;
std::tie(id, ud, bk) = kv.first; if (!gainValid[id][ud][bk]) continue;
if (!gainValid[id][ud][bk]) double gain = gainArray[id][ud][bk];
continue;
auto &pts = kv.second; for (const auto &pr : kv.second)
for (auto &pr : pts)
{ {
double corrBack = pr.first * gainArray[id][ud][bk]; double eBk, eUp, eDn;
double udE = pr.second; std::tie(eBk, eUp, eDn) = pr;
hAll->Fill(corrBack, udE);
double updn = eUp + eDn;
if (updn == 0) continue;
double asym = (eUp - eDn) / updn;
double correctedBack = eBk * gain;
hFVB->Fill(correctedBack, updn);
hAsym->Fill(eUp/eBk,eDn/eBk);
} }
} }
// Optional: save histograms to a file
// TFile *outHist = new TFile("sx3_gainmatch_hists.root", "RECREATE");
// hFVB->Write();
// hAsym->Write();
// outHist->Close();
} }