XIAEventBuilder/JakeStuff/drawTimeDiffHists.cpp

70 lines
2.2 KiB
C++

// Function for GeTimeDiff histograms with 00, 01, 02, ... naming
void drawGeTimeDiffHistograms(const char* filename) {
TFile* file = TFile::Open(filename, "READ");
if (!file || file->IsZombie()) {
std::cerr << "Error: Cannot open file " << filename << std::endl;
return;
}
std::vector<TH1*> histograms;
std::vector<int> foundIndices;
// Look for histograms with GeTimeDiff00, GeTimeDiff01, etc.
for (int i = 0; i < 66; i++) {
TString histName = Form("GeTimeDiff%02d", i); // %02d gives 00, 01, 02, etc.
TH1* hist = (TH1*)file->Get(histName);
if (hist) {
histograms.push_back(hist);
foundIndices.push_back(i);
std::cout << "Found: " << histName << std::endl;
}
}
if (histograms.empty()) {
std::cerr << "No GeTimeDiff histograms found!" << std::endl;
file->Close();
return;
}
std::cout << "Found " << histograms.size() << " GeTimeDiff histograms" << std::endl;
// Create canvas with appropriate divisions
int nCols = 11;
int nRows = 6;
TCanvas* canvas = new TCanvas("canvas", "GeTimeDiff Histograms", 1920, 1080);
canvas->Divide(nCols, nRows);
// Draw histograms
for (int i = 0; i < histograms.size(); i++) {
canvas->cd(i + 1);
gPad->SetLeftMargin(0.12);
gPad->SetRightMargin(0.05);
gPad->SetTopMargin(0.1);
gPad->SetBottomMargin(0.12);
gPad->SetLogy();
histograms[i]->Draw();
// Adjust text sizes for better visibility
histograms[i]->SetTitleSize(0.06, "t");
histograms[i]->SetTitleSize(0.05, "x");
histograms[i]->SetTitleSize(0.05, "y");
histograms[i]->SetLabelSize(0.04, "x");
histograms[i]->SetLabelSize(0.04, "y");
// Add histogram index as subtitle
histograms[i]->SetTitle(Form("GeTimeDiff%02d", foundIndices[i]));
}
canvas->Update();
canvas->SaveAs("GeTimeDiff_all.pdf");
std::cout << "Canvas saved as GeTimeDiff_all.png and GeTimeDiff_all.pdf" << std::endl;
}
// Usage examples:
// root -l 'drawAllHistograms("yourfile.root")'
// root -l 'drawGeTimeDiffHistograms("yourfile.root")'