#include #include #include #include void plotHistograms() { // Open the ROOT file TFile *file = new TFile("-200V_pulsgraph.root", "READ"); // Check if the file is open successfully if (!file->IsOpen()) { std::cerr << "Error: Unable to open file!" << std::endl; return; } // Access the histograms TH1F *hist1 = (TH1F*)file->Get("PulseTransfer/mydetector/pulses_induced_profile"); TH1F *hist2 = (TH1F*)file->Get("PulseTransfer/mydetector/pulses_integrated_profile"); // Check if histograms are retrieved successfully if (!hist1 || !hist2) { std::cerr << "Error: Unable to retrieve histograms from file!" << std::endl; file->Close(); return; } // Create a canvas TCanvas *canvas = new TCanvas("canvas", "Histograms", 1200, 600); canvas->Divide(2, 1); // Rescale x-axis hist1->GetXaxis()->SetRangeUser(0/* Your x-axis minimum */, 30/* Your x-axis maximum */); hist2->GetXaxis()->SetRangeUser(0/* Your x-axis minimum */,30 /* Your x-axis maximum */); // Plot histograms canvas->cd(1); hist1->Draw(); canvas->cd(2); hist2->Draw(); // Close the file file->Close(); // Save the canvas as an image (optional) canvas->SaveAs("histograms.png"); // Delete objects to free memory delete hist1; delete hist2; delete file; delete canvas; } int main() { plotHistograms(); return 0; }