THStack with TProfile

THStack doesn’t seems to work propertly with TProfile

TProfile prof("prof", "prof", 100, -2.5, 2.5)
prof.Fill(0, 1)
prof.Fill(0, 1)
TProfile prof2("prof2", "prof2", 100, -2.5, 2.5)
prof2.Fill(0, 0.5)
prof2.Fill(0, 0.5)
THStack hs("stack", "stack")
hs.Add(&prof)
hs.Add(&prof2)
hs.SetMaximum(2)
hs.Draw("histo")

I can see only the first one

{
   TProfile *prof1 = new TProfile("prof1", "prof1", 100, -2.5, 2.5);
   prof1->Fill(0, 1);
   prof1->Fill(0, 1);
   prof1->SetFillColor(4);
   TProfile *prof2 = new TProfile("prof2", "prof2", 100, -2.5, 2.5);
   prof2->Fill(0.1, 0.5);
   prof2->Fill(0.1, 0.5);
   prof2->SetFillColor(2);
   THStack hs("stack", "stack");
   hs->Add(prof1);
   hs->Add(prof2);
   hs->SetMaximum(2);
   hs->Draw("HIST");
}

Yes in fact as you can see on this modified version of you macro the 2 histos are not superimposed… but both are drawn

[quote=“couet”] { TProfile *prof1 = new TProfile("prof1", "prof1", 100, -2.5, 2.5); prof1->Fill(0, 1); prof1->Fill(0, 1); prof1->SetFillColor(4); TProfile *prof2 = new TProfile("prof2", "prof2", 100, -2.5, 2.5); prof2->Fill(0.1, 0.5); prof2->Fill(0.1, 0.5); prof2->SetFillColor(2); THStack hs("stack", "stack"); hs->Add(prof1); hs->Add(prof2); hs->SetMaximum(2); hs->Draw("HIST"); }
Yes in fact as you can see on this modified version of you macro the 2 histos are not superimposed… but both are drawn[/quote]

thanks, but the THStack must stack them

I asked Lorenzo (our math expert) who told no that it does not really make sense to stack profile histograms. If you want to make a stack convert them to normal TH1.

yes, I’m exactly doint that. I’m wondering if you can automatize it, so when adding a TProfile to a THStack convert automaticcaly it to a TH1.

It does not make sense to stack profile plots, so we cannot have this functionality automatically. It is the user who needs to do the projection of TProfile in a TH1, according to its needs

Best Regards

Lorenzo

[quote=“moneta”]It does not make sense to stack profile plots, so we cannot have this functionality automatically. It is the user who needs to do the projection of TProfile in a TH1, according to its needs

Best Regards

Lorenzo[/quote]

ok, but if it doesn’t make sense the function THStack::Add should not take as argument a TProfile

Yes, you are right, we should probably add an error message since we cannot exclude it at compile time, since
we have unfortunately a TProfile deriving from a TH1.
Thank you for the suggestion

Lorenzo