Quick question on multiple TProfiles

Dear rooters,
I have a quick question. I have been trying to draw multiple profile histograms on the same canvas but have been unable to. The code somehow gives me always the last one, there should be something very trivial here that I’m missing. I see a warning [1] showing up every time the profile is created in the next iteration.
I paste below [2] the relevant part of the code. I tried getting the profile histogram saving into a TProfile and then drawing using local definition and arrays of TProfiles, but doesn’t work.
Could someone please point out and help?

Thanks in advance & Best regards
[1] : Warning in : Sum of squares of profile bin weights structure already created


{ const int nfiles = 2;
std::string file_names[nfiles] = {

for(int ifile = 0; ifile < nfiles; ifile++)
TFile *_file0 = TFile::Open(file_names[ifile].c_str());
if(ifile == 0)

Try: for (int i = 0; i < nfiles; i++) { TFile *f = TFile::Open(file_names[i].c_str()); TH2 *h; f->GetObject("h1", h); if (h) { TProfile *h_pfx = h->ProfileX(Form("%s_pfx_%i", h->GetName(), i)); if (!i) h_pfx->Draw("hist c"); else h_pfx->Draw("hist c sames"); } }

Thanks a lot. It works well. I tried using earlier:
TProfile *h_pfx = h->ProfileX();
I didn’t know I could name TProfiles the way you mentioned.

Thanks again for your help and best regards