Hi everyone, I have a canvas which I divided into 4 and I would like to add text to each pad. The text would be different for the different pads, so I tried to access each pad individually with c->cd() and then add the text for that pad. However, when I run my macro, all the text is printed on top of each other in my last pad. I don’t know what I am doing wrong here. Many thanks!
#include "TFile.h"
#include "TCanvas.h"
#include "TH1.h"
#include "TMultiGraph.h"
#include "TGraphAsymmErrors.h"
#include "TString.h"
#include <vector>
#include <iostream>
void mjj_eff_tc_ntc(const char *fname = "HaddOutput_old.root") {
if (!(fname && fname[0])) return; // just a precaution
TFile *f = TFile::Open(fname);
if ((!f) || f->IsZombie()) { delete f; return; } // just a precaution
std::vector<std::string> TriggerCut = {"L1_J20", "L1_J40", "L1_J50", "L1_J100"};
std::vector<int> pT1Cut = {85, 130, 145, 220};
std::vector<int> pT2Cut = {60, 70, 85, 90, 100, 110, 120, 130, 145, 150, 160, 170, 185, 190, 200, 210, 220};
int n = TriggerCut.size();
int n1 = pT1Cut.size();
int n2 = pT2Cut.size();
TCanvas *c = new TCanvas("c", "", (n1 * 350), 1000);
c->Divide(2, 2);
c->SetFillColor(0);
TH1D *h[n];
TH1D *s[n][n1];
TH1D *m[n][n1][n2];
TMultiGraph *mg[n];
TGraphAsymmErrors *eff[n][n1][n2];
TLegend *legend[n];
TH1D *histo1[n];
TH1D *histo2[n][n1];
for (int i = 0; i < n; i++) {
c->cd(i + 1);
f->GetObject(TString::Format("%s/yCut_0.6/pT1Cut_0/pT2Cut_0/Mjj", TriggerCut[i].c_str()), h[i]);
if (!h[i]) continue; // just a precaution
mg[i] = new TMultiGraph();
for (int j = 0; j < n1; j++) {
if (j != i) continue;
f->GetObject(TString::Format("%s/yCut_0.6/pT1Cut_%d/pT2Cut_0/Mjj", TriggerCut[i].c_str(), pT1Cut[j]), s[i][j]);
f->GetObject(TString::Format("AfterCuts/yCut_0.6/pT1Cut_%d/pT2Cut_0/Mjj", pT1Cut[j]), histo1[j]);
for (int k = 0; k < n2; k++) {
if (pT2Cut[k] > pT1Cut[j]) continue; // skip unwanted
if (j == 1 && pT2Cut[k] < 110) continue;
if (j == 2 && pT2Cut[k] < 120) continue;
if (j == 3 && pT2Cut[k] < 200) continue;
f->GetObject(TString::Format("%s/yCut_0.6/pT1Cut_%d/pT2Cut_%d/Mjj", TriggerCut[i].c_str(), pT1Cut[j], pT2Cut[k]), m[i][j][k]);
f->GetObject(TString::Format("AfterCuts/yCut_0.6/pT1Cut_%d/pT2Cut_%d/Mjj", pT1Cut[j], pT2Cut[k]), histo2[j][k]);
eff[i][j][k] = new TGraphAsymmErrors();
eff[i][j][k]->Divide(m[i][j][k], histo2[j][k], "n");
eff[i][j][k]->SetMarkerSize(0.5);
mg[i]->Add(eff[i][j][k], "p");
}
}
mg[i]->Draw("AL");
}
c->cd(1);
TLatex text1(62,1,"#splitline{L1_J20}{|y*| < 0.6}");
text1.SetTextSize(0.05);
text1.DrawClone();
c->cd(2);
TLatex text2(62,1,"#splitline{L1_J40}{|y*| < 0.6}");
text2.SetTextSize(0.05);
text2.DrawClone();
}