TColor

Hi there,

I have been trying to use the TColor options to fill my histograms, but I can’t, when I used for example h->SetLineColor(kOrange); I got ./tools/T1transversemassfinal01colorprobe.cc: In function ‘void prepare(TH1F*)’:
./tools/T1transversemassfinal01colorprobe.cc:45: error: ‘kOrange’ was not declared in this scope

I used #include <Rtypes.h>
#include <TColor.h>

I also tried with #include <TNamed.h>, but I got the same, and when I use kRed+3 I got green plots. What do I have to check in order to make it works?

Example:

{
  TCanvas *c1 = new TCanvas("c1","c1",800,600);
  TH1F *h1 = new TH1F("h1","Histo 1",100,-5,5);
  h1->FillRandom("gaus",10000);
  h1->SetFillColor(kOrange);
  h1->Draw();
}

I am using it in this way

#include <iostream.h>
#include <stdlib.h>
#include “T1_McAtNlo.hh”
#include “TCanvas.h”
#include <TLorentzVector.h>
#include “TH1.h”
#include “TF1.h”
#include “TGraphErrors.h”
#include <vector.h>
#include <iostream.h>
#include <TLatex.h>
#include <Rtypes.h>
//#include <TNamed.h>
#include <TColor.h>
#include <TAttFill.h>
#include “wp_fullv12064.hh”

void prepare(TH1F *h) {

    h->SetLineColor(kOrange);
 //h->SetFillColor(46);		
 // h->SetFillStyle(6004);	
 //h->Fit("gaus");
 h->SetMinimum(1e-8);
 h->SetMaximum(5e-3);
 h->SetLineWidth(2);
     h->GetXaxis()->SetTitle("M_{t} [TeV]");
 h->GetYaxis()->SetTitle("Cross section [fb]");
 //h->GetYaxis()->SetTitle("Mean value");	

}

With this macro you change the line color not the fill color.

sorry, It appears as commented, but that is because I have been trying a lot of options to get the colors, the fact is that when I compile it says that:

./tools/T1transversemassfinal01colorprobe.cc:47: error: ‘kOrange’ was not declared in this scope
./tools/T1transversemassfinal01colorprobe.cc: In function ‘int main(int, char**)’:

even using the corresponding headers.

thank you.

kOrange is defined in Rtypes.h.

I am using it …

Ah, yes… but you do the include with <…> not with “…” like for TCanvas …
Can you try to do the same as for TCanvas ?

I changed all the “…” by <…>, except for two… and I am still getting

‘kOrange’ was not declared in this scope

#include <iostream.h>
#include <stdlib.h>
#include “T1_McAtNlo.hh”
#include <TCanvas.h>
#include <TLorentzVector.h>
#include <TH1.h>
#include <TF1.h>
#include <TGraphErrors.h>
#include <vector.h>
#include <iostream.h>
#include <TLatex.h>
#include <Rtypes.h>
//#include <TNamed.h>
#include <TColor.h>
#include <TAttFill.h>
#include “wp_fullv12064.hh”

I do not see your problem with a little program I wrote:

#include <TColor.h>                                                                                
int main() {
   printf(" kOrange = %d\n",kOrange);
}

I compile it using:

g++ -c main.cxx -I$ROOTSYS/include

and it is working. Note that you can also include Rtypes.h instead of TColor.h, it is working also.

To use kOrange, etc, you must use one of the latest versions of ROOT, eg 5.16
see root.cern.ch/root/Version516.news.html
and look for teh explanation of teh color code in the section TColorWheel.

Rene

Yes, it was the ROOT version, now I have ROOT 5.16, now I do not have problems with the compilation, but when I run the executable, I got errors with the branchs

Error in TChain::SetBasketSize: unknown branch -> 'RunNumber’
Error in TChain::SetBasketSize: unknown branch -> 'EventNumber’
Error in TChain::SetBasketSize: unknown branch -> 'StreamESD_ref’
Error in TChain::SetBasketSize: unknown branch -> 'StreamRDO_ref’
Error in TChain::SetBasketSize: unknown branch -> 'Token’
Error in TChain::SetBasketSize: unknown branch -> ‘Run’

did I miss something?

thank you,

problem solved, I did not compile the headers with the new version,
thank you very much