Hist->SetFillColor

Dear experts,

I called the hist->SetFillColor(a_color), see[1], for my hist but when I open the root file, the hist is not fill. When I use the hist->SetLineColor(a_color) everything work. Can you please tell me what is wrong?

[1]
code.h
for(int i=0; i<9; i++) {
hmass[i] = new TH1D(vdir[i].c_str(), vdir[i].c_str(), 200, 0, 3000);
hmass[i]->SetLineWidth(2);
if(sample.find(“M50”) !=std::string::npos) hmass[i]->SetFillColor(kGreen);
if(sample.find(“M125”) !=std::string::npos) hmass[i]->SetFillColor(kRed);
if(sample.find(“M200”) !=std::string::npos) hmass[i]->SetFillColor(kMagenta);
if(sample.find(“M300”) !=std::string::npos) hmass[i]->SetFillColor(kBlue);
}

code.C
void SVfitMEM::Loop(){
for (Long64_t jentry=0; jentry<nentries;jentry++) {

   hmass[0] ->Fill(Mass0);
   hmass[1] ->Fill(Mass1);
    ...
   hmass[9] ->Fill(svfitMass9);
  }
for(int i=0; i<9; i++) hmass[i]->Write(); 

}

It works for me. See the attached picture.


Dear Couet,

my code is more complicate then yours. Maybe something wrong is happening but the SetFillColor is not working. I send you the code that I’m using, can you please have a look, do you see something wrong?

1- file.h
2- file.C
3- main.cc
4- root file: calpas.web.cern.ch/calpas/svFitS … 0_all.root
5- makefile: calpas.web.cern.ch/calpas/Makefile

you can run with:
1- make
2- ./do.exe

this will create a root file in which the hist are not Fill with color.

Regards
main.cc (2.33 KB)
SVfitMEM.C (4.52 KB)
SVfitMEM.h (33.1 KB)

cannot download the makefile

Can you please try again, and use this new main.cc.

Regards
main.cc (2.32 KB)

When I click on the link to get your Makefile I get an error 404…
May be just attached it here.

Sorry! it’s working now…

Your histograms have error bars. By default they are plotter suing error bars. If you what to see them as bar chart do:

hadhad_smeared_vismass->Draw("hist");

Dear couet,

what I want is to see the hist fill with color when using hist->SetFillColor(color).
right now I’m writing the hist in a root file (no ->Draw()) involve.
Where do you want me to call a Draw(“hist”)?
when I did at line 124 of file.C:
for(int i=0; i<9; i++) { hmass[i]->Draw(“hist”); hmass[i]->Write(); }
it still not working. Do you know what is wrong?

Regards

Yes you write the histograms… I got that… and they are stored with the correct fill color… you can see that when later you Draw them with the “hist” option .

Now the question is: how did you see it is not working ?

Dear Couet,

ok I got it! using ->Draw(“hist”) fixed the issue.
Thank you for your help.

Regards

=D>

:smiley: