diff --git a/RunTimeSummary.C b/RunTimeSummary.C new file mode 100644 index 0000000..0b53bb6 --- /dev/null +++ b/RunTimeSummary.C @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include +#include +#include + +void RunTimeSummary(int startRun, int endRun) +{ + TString fileDir = "/mnt/d/Remapped_files/17F_data/root_data/"; + TString histName = "AnodeQQQ_Time"; + TString filePattern = "Run_%03d_mapped_histograms.root"; + TString filePatternAlt = "ProtonRun_%d_mapped_histograms.root"; + TString filePatternAlt2 = "Source_%d_mapped_histograms.root"; + + int nBinsTime = 0; + double timeMin = 0, timeMax = 0; + bool foundRef = false; + + for (int r = startRun; r <= endRun; r++) + { + TString tempName; + + // 1. Try Pattern 1: Run_XXX... + tempName = fileDir + Form(filePattern, r); + if (gSystem->AccessPathName(tempName)) + { // Returns true if MISSING + + // 2. Try Pattern 2: ProtonRun_X... + tempName = fileDir + Form(filePatternAlt, r); + if (gSystem->AccessPathName(tempName)) + { + + // 3. Try Pattern 3: Source_X... + tempName = fileDir + Form(filePatternAlt2, r); + if (gSystem->AccessPathName(tempName)) + { + // All 3 patterns failed. Skip this run. + continue; + } + } + } + + // If we get here, 'tempName' holds the valid filename that was found + TFile *fTemp = TFile::Open(tempName); + if (!fTemp || fTemp->IsZombie()) + { + if (fTemp) + delete fTemp; + continue; + } + + TH1F *hRef = (TH1F *)fTemp->Get(histName); + if (hRef) + { + + nBinsTime = hRef->GetNbinsX(); + timeMin = hRef->GetXaxis()->GetXmin(); + timeMax = hRef->GetXaxis()->GetXmax(); + foundRef = true; + + delete hRef; + fTemp->Close(); + delete fTemp; + printf("Reference found in Run %d: %d bins, Range [%.1f, %.1f]\n", r, nBinsTime, timeMin, timeMax); + break; + } + fTemp->Close(); + delete fTemp; + } + + if (!foundRef) + { + printf("Error: No valid histograms found in the entire range. Exiting.\n"); + return; + } + + int nRuns = endRun - startRun + 1; + TH2F *hSummary = new TH2F("hSummary", + Form("Timing Summary (Runs %d-%d);Timing;Run Number", startRun, endRun), + nBinsTime, timeMin, timeMax, + nRuns, startRun, endRun + 1); + + for (int run = startRun; run <= endRun; run++) + { + + TString filename = fileDir + Form(filePattern, run); + + if (gSystem->AccessPathName(filename)) + continue; + + TFile *fin = TFile::Open(filename); + if (!fin || fin->IsZombie()) + { + if (fin) + delete fin; + continue; + } + + TH1F *hin = (TH1F *)fin->Get(histName); + + if (hin) + { + // Determine which ROW (Y-bin) corresponds to this Run + // Note: ROOT bins start at 1. + // If startRun=10 and run=10 -> binY=1. + int binY_Run = run - startRun + 1; + + // Loop through the Time bins (X-bins in the 1D hist) + for (int binX_Time = 1; binX_Time <= hin->GetNbinsX(); binX_Time++) + { + + double content = hin->GetBinContent(binX_Time); + + // Copy content to: (Time, Run) + if (content > 0) + { + hSummary->SetBinContent(binX_Time, binY_Run, content); + } + } + delete hin; + } + + fin->Close(); + delete fin; + + if ((run - startRun) % 10 == 0) + printf("Stitched Run %d...\n", run); + } + + TFile *fOut = new TFile("SummaryPlot.root", "RECREATE"); + hSummary->Write(); + + TCanvas *c1 = new TCanvas("c1", "Time Summary Plot", 1000, 800); + hSummary->SetStats(0); + hSummary->Draw("COLZ"); + + printf("Done! Saved to SummaryPlot.root\n"); +} \ No newline at end of file diff --git a/Timing_Summary_Matplotlib.png b/Timing_Summary_Matplotlib.png new file mode 100644 index 0000000..a5178ea Binary files /dev/null and b/Timing_Summary_Matplotlib.png differ diff --git a/TrackRecon.C b/TrackRecon.C index 56e8797..09d6d89 100644 --- a/TrackRecon.C +++ b/TrackRecon.C @@ -42,15 +42,16 @@ bool HitNonZero; bool sx3ecut; bool qqqEcut; -void TrackRecon::Begin(TTree * tree) -{ //get file name - std::cout<GetCurrentFile()->GetName()<GetCurrentFile()->GetName() << std::endl; + // get substring from file name to identify run number TString option = GetOption(); std::string treefilename(tree->GetCurrentFile()->GetName()); - plotter = new HistPlotter(treefilename.substr(0,treefilename.length()-std::string(".root").length())+"_histograms.root", "TFILE"); + plotter = new HistPlotter(treefilename.substr(0, treefilename.length() - std::string(".root").length()) + "_histograms.root", "TFILE"); + // plotter = new HistPlotter("Analyzer.root", "TFILE"); pw_contr.ConstructGeo(); pwinstance.ConstructGeo(); @@ -88,7 +89,7 @@ void TrackRecon::Begin(TTree * tree) Crossover[i][j][0].y = pwinstance.An[i].first.Y() + alpha * a.Y(); Crossover[i][j][0].z = pwinstance.An[i].first.Z() + alpha * a.Z(); - if (Crossover[i][j][0].z < -190 || Crossover[i][j][0].z > 190) + if (Crossover[i][j][0].z < -190 || Crossover[i][j][0].z > 190 || (i + j) % 24 == 12) { Crossover[i][j][0].z = 9999999; } @@ -99,7 +100,7 @@ void TrackRecon::Begin(TTree * tree) } // Load PC Calibrations - std::ifstream inputFile("slope_intercept_results.txt"); + std::ifstream inputFile("slope_intercept_results.dat"); if (inputFile.is_open()) { std::string line; @@ -324,7 +325,7 @@ Bool_t TrackRecon::Process(Long64_t entry) plotter->Fill2D("DelT_Vs_QQQRingECal", 500, -2500, 2500, 1000, 0, 10, tRing - static_cast(pc.t[k]), eRingMeV, "hTiming"); plotter->Fill2D("CalibratedQQQEvsAnodeE_R", 1000, 0, 10, 2000, 0, 30000, eRingMeV, pc.e[k], "hPCQQQ"); plotter->Fill2D("CalibratedQQQEvsAnodeE_W", 1000, 0, 10, 2000, 0, 30000, eWedgeMeV, pc.e[k], "hPCQQQ"); - if (tRing - static_cast(pc.t[k]) < -150 && tRing - static_cast(pc.t[k]) > -450) // 27Al + if (tRing - static_cast(pc.t[k]) < -150) // 27Al // if (tRing - static_cast(pc.t[k]) < -75 && tRing - static_cast(pc.t[k]) > -145) // 17F { PCQQQTimeCut = true; @@ -338,7 +339,7 @@ Bool_t TrackRecon::Process(Long64_t entry) } double theta = -TMath::Pi() / 2 + 2 * TMath::Pi() / 16 / 4. * (qqq.id[i] * 16 + chWedge + 0.5); - double rho = 50. + 40. / 16. * (chRing + 0.5); + double rho = 50. + 50. / 16. * (chRing + 0.5); plotter->Fill2D("QQQPolarPlot", 16 * 4, -TMath::Pi(), TMath::Pi(), 32, 40, 100, theta, rho, "hCalQQQ"); plotter->Fill2D("QQQCartesianPlot", 200, -100, 100, 200, -100, 100, rho * TMath::Cos(theta), rho * TMath::Sin(theta), "hCalQQQ"); @@ -507,7 +508,7 @@ Bool_t TrackRecon::Process(Long64_t entry) ; // to ignore events with no valid crossover points else - anodeIntersection = TVector3(x, y, -z); + anodeIntersection = TVector3(x, y, z); // std::cout << "Anode Intersection: " << anodeIntersection.X() << ", " << anodeIntersection.Y() << ", " << anodeIntersection.Z() << std::endl; } bool PCQQQPhiCut = false; @@ -517,36 +518,41 @@ Bool_t TrackRecon::Process(Long64_t entry) PCQQQPhiCut = true; } - // for (double Tz = -190; Tz <= 190; Tz += 10.0) - // { - // TVector3 TargetPos(0, 0, Tz); - // plotter->Fill2D("Inttheta_vs_QQQtheta_TC" + std::to_string(PCQQQTimeCut) + "_TZ" + std::to_string(Tz), 90, 0, 180, 120, 0, 180, (anodeIntersection - TargetPos).Theta() * 180. / TMath::Pi(), (hitPos - TargetPos).Theta() * 180. / TMath::Pi(), "TPosVariation"); - // } + for (double AIz = 20; AIz <= 100; AIz += 5.0) + { + TVector3 TargetPos(0, 0, AIz); + if (PCQQQPhiCut && anodeIntersection.Perp() != 0 && cathodeHits.size() >= 2) + // TVector3 anodePosAtZ(anodeIntersection.X() * (AIz / anodeIntersection.Z()), anodeIntersection.Y() * (AIz / anodeIntersection.Z()), AIz); + // TVector3 anodePosAtZ(anodeIntersection.X(), anodeIntersection.Y(),anodeIntersection.Z() + AIz); + plotter->Fill2D("Inttheta_vs_QQQtheta_TC" + std::to_string(PCQQQTimeCut) + "_TZ" + std::to_string(AIz), 180, 0, 180, 90, 0, 90, (anodeIntersection - TargetPos).Theta() * 180. / TMath::Pi(), + (hitPos - TargetPos).Theta() * 180. / TMath::Pi(), "TPosVariation"); + } - if (anodeIntersection.Z() != 0) + if (anodeIntersection.Perp() != 0) { plotter->Fill1D("PC_Z_Projection", 600, -300, 300, anodeIntersection.Z(), "hPCzQQQ"); plotter->Fill2D("Z_Proj_VsDelTime", 600, -300, 300, 200, -2000, 2000, anodeIntersection.Z(), anodeT - cathodeT, "hPCzQQQ"); plotter->Fill2D("IntPhi_vs_QQQphi", 100, -200, 200, 80, -200, 200, anodeIntersection.Phi() * 180. / TMath::Pi(), hitPos.Phi() * 180. / TMath::Pi(), "hPCQQQ"); + plotter->Fill1D("IntRho", 200, 0, 100, anodeIntersection.Perp(), "hRawPC"); plotter->Fill2D("Inttheta_vs_QQQtheta", 90, 0, 180, 20, 0, 45, anodeIntersection.Theta() * 180. / TMath::Pi(), hitPos.Theta() * 180. / TMath::Pi(), "hPCQQQ"); plotter->Fill2D("Inttheta_vs_QQQtheta_TC" + std::to_string(PCQQQTimeCut), 90, 0, 180, 20, 0, 45, anodeIntersection.Theta() * 180. / TMath::Pi(), hitPos.Theta() * 180. / TMath::Pi(), "hPCQQQ"); plotter->Fill2D("IntPhi_vs_QQQphi_TC" + std::to_string(PCQQQTimeCut) + "PhiC" + std::to_string(PCQQQPhiCut), 100, -200, 200, 80, -200, 200, anodeIntersection.Phi() * 180. / TMath::Pi(), hitPos.Phi() * 180. / TMath::Pi(), "hPCQQQ"); } - if (anodeIntersection.Z() != 0 && cathodeHits.size() >= 2) + if (anodeIntersection.Perp() != 0 && cathodeHits.size() >= 2) plotter->Fill1D("PC_Z_Projection_TC" + std::to_string(PCQQQTimeCut) + "PhiC" + std::to_string(PCQQQPhiCut), 600, -300, 300, anodeIntersection.Z(), "hPCzQQQ"); - if (anodeIntersection.Z() != 0 && cathodeHits.size() == 1) + if (anodeIntersection.Perp() != 0 && cathodeHits.size() == 1) { plotter->Fill1D("PC_Z_proj_1C", 600, -300, 300, anodeIntersection.Z(), "hPCzQQQ"); plotter->Fill2D("IntersectionPhi_vs_AnodeZ_1C", 400, -200, 200, 600, -300, 300, anodeIntersection.Phi() * 180. / TMath::Pi(), anodeIntersection.Z(), "hPCzQQQ"); } - if (anodeIntersection.Z() != 0 && cathodeHits.size() == 2) + if (anodeIntersection.Perp() != 0 && cathodeHits.size() == 2) { plotter->Fill1D("PC_Z_proj_2C", 600, -300, 300, anodeIntersection.Z(), "hPCzQQQ"); plotter->Fill2D("IntersectionPhi_vs_AnodeZ_2C", 400, -200, 200, 600, -300, 300, anodeIntersection.Phi() * 180. / TMath::Pi(), anodeIntersection.Z(), "hGMPC"); } - if (anodeIntersection.Z() != 0 && cathodeHits.size() > 2) + if (anodeIntersection.Perp() != 0 && cathodeHits.size() > 2) { plotter->Fill1D("PC_Z_proj_nC", 600, -300, 300, anodeIntersection.Z(), "hPCzQQQ"); plotter->Fill2D("IntersectionPhi_vs_AnodeZ_nC", 400, -200, 200, 600, -300, 300, anodeIntersection.Phi() * 180. / TMath::Pi(), anodeIntersection.Z(), "hGMPC"); @@ -615,8 +621,8 @@ Bool_t TrackRecon::Process(Long64_t entry) { if (cathodeHits.size() == 2) plotter->Fill1D("VertexRecon_TC_PhiC_2C", 600, -300, 300, pw_contr.GetZ0()); - } - plotter->Fill1D("VertexRecon_TC" + std::to_string(PCQQQTimeCut) + "_PhiC" + std::to_string(PCQQQPhiCut), 600, -300, 300, pw_contr.GetZ0()); + } + plotter->Fill1D("VertexRecon_TC" + std::to_string(PCQQQTimeCut) + "_PhiC" + std::to_string(PCQQQPhiCut), 600, -300, 300, pw_contr.GetZ0()); } for (int i = 0; i < qqq.multi; i++) @@ -691,11 +697,12 @@ Bool_t TrackRecon::Process(Long64_t entry) plotter->Fill2D("PC_Z_vs_QQQRing_Det" + std::to_string(qqqID), 600, -300, 300, 16, 0, 16, anodeIntersection.Z(), chRing, "hPCQQQ"); for (int k = 0; k < pc.multi; k++) { - if(pc.index[k] >= 24) - continue; + if (pc.index[k] >= 24) + continue; plotter->Fill2D("CalibratedQQQE_RvsAnodeE_TC" + std::to_string(PCQQQTimeCut) + "PhiC" + std::to_string(PCQQQPhiCut), 1000, 0, 10, 2000, 0, 30000, eRingMeV, pc.e[k], "hPCQQQ"); plotter->Fill2D("CalibratedQQQE_WvsAnodeE_TC" + std::to_string(PCQQQTimeCut) + "PhiC" + std::to_string(PCQQQPhiCut), 1000, 0, 10, 2000, 0, 30000, eWedgeMeV, pc.e[k], "hPCQQQ"); - plotter->Fill2D("AnodeQQQ_dTimevsdPhi", 200, -2000, 2000, 80, -200, 200, tRing - static_cast(pc.t[k]), (hitPos.Phi()-anodeIntersection.Phi()) * 180. / TMath::Pi(), "hTiming"); + plotter->Fill2D("AnodeQQQ_dTimevsdPhi", 200, -2000, 2000, 80, -200, 200, tRing - static_cast(pc.t[k]), (hitPos.Phi() - anodeIntersection.Phi()) * 180. / TMath::Pi(), "hTiming"); + plotter->Fill1D("AnodeQQQ_Time", 200, -2000, 2000, tRing - static_cast(pc.t[k])); } } } diff --git a/process_mapped_run.sh b/process_mapped_run.sh index 6d7b88c..29f3827 100755 --- a/process_mapped_run.sh +++ b/process_mapped_run.sh @@ -3,7 +3,7 @@ # ========================================== # CONFIGURATION # ========================================== -DATA_DIR="/mnt/d/Remapped_files/17F_data/root_data" +DATA_DIR="/mnt/d/Remapped_files/27Al_data/root_data" MACRO="TrackRecon.C" # SAFETY SETTINGS