Hi,
I am working building a THStack from several histograms on a single canvas. I would like to plot the histograms with only markers and no error bars, Unlike what I see in the attached figure, I would like remove the error bars. Could you help me how to do that. I add the macro that use to plot the histos below:
void processHistograms(const char* filename) {
// Open the file
TFile *file = TFile::Open(filename);
if (!file || file->IsZombie()) {
std::cerr << "Error opening file: " << filename << std::endl;
return;
}
// Create a canvas
TCanvas *c = new TCanvas("c", "Canvas", 800, 800);
gStyle->SetOptTitle(kFALSE);
gStyle->SetOptStat(0);
// Create a THStack
THStack *hStack__Regions = new THStack("hStack_MM_ppLLKX_Regions", "Missing Mass from the Regions on correlation plot; Missing Mass (M_{X}) [MeV/c^{2}]; Counts");
// Create a legend
// TLegend *legend = new TLegend(0.7, 0.7, 0.9, 0.9); // Adjust these coordinates as needed
// An array for choosing colour and marker style
Int_t a_colour[8] = {1, 2, 3, 4, 6, 7, 8, 9};
Int_t a_marker[8] = {2, 3, 4, 6, 25, 26, 27, 28};
// Loop over the histograms
for (int i = 1; i <= 9; ++i) {
// Construct the histogram name
TString histName = Form("hMissingMass_DCACut2_R%d", i);
// Retrieve the histogram
TH1F *hist = (TH1F*)file->Get(histName);
if (!hist) {
std::cerr << "Histogram not found: " << histName << std::endl;
continue;
}
// Set the maximum of the y-axis
// hist->SetMaximum(120);
// Set a unique marker style for each histogram
hist->SetLineColor(a_colour[i]);
hist->Scale(0.99999999);
hist->SetMarkerStyle(a_marker[i]);
hist->SetMarkerStyle(a_marker[i]);
hist->SetMarkerColor(a_colour[i]);
TString legendEntry = Form("Region %d", i);
hist->SetTitle(legendEntry);
// Add the histogram to the stack
hStack_Regions->Add(hist);
// Add the histogram to the legend
// legend->AddEntry(hist, legendEntry, "l");
// Draw the histogram with the "P" option to apply marker styles
// hist->Draw("SAME PLC PMC");
}
// Draw the THStack on the canvas
hStack_Regions->Draw("NOSTACK, PLC"); // Use "NOSTACK" to draw histograms side by side
// Draw the legend
// legend->Draw();
c->Update();
gPad->BuildLegend();
// Close the file
// file->Close();
}
MM_Regions_errbars.pdf (84.9 KB)