For some reason this seems to do the opposite of what I want it to do. When I do
h3->DrawCopy();
h3->SetLineColor(kBlack);
on c3, the histogram is turned black on c2 but remains red on c3. I assume this is because doing DrawCopy() creates a new object, which is not the same one as I access when doing h3->SetLineColor();.
Is there a way of accessing this new object or should I simply reverse the declarations of kBlack and kRed?
PS: doing TH1F* h3_copy = h3->DrawCopy(); gives me the error: "cannot initialize a variable of type ‘TH1F *’ with an rvalue of type 'TH1 '", even though h3 is initialised as a TH1F
#include "TH1.h"
#include "TCanvas.h"
/// I would like the colour of h3 to be kRed in c2 but kBlack in c3
void TH1FCopyTest(){
TH1F* h1 = new TH1F("h1","h1",6,0,6);
TH1F* h2 = new TH1F("h2","h2",6,0,6);
TH1F* h3 = new TH1F("h3","h3",6,0,6);
h1->Fill(1);
h2->Fill(3);
h3->Fill(5);
h1->SetLineWidth(5);
h2->SetLineWidth(5);
h3->SetLineWidth(5);
TCanvas* c1 = new TCanvas("c1","c1",0,0,800,800);
h1->Draw();
h2->Draw("same");
h2->SetLineColor(kRed);
TCanvas* c2 = new TCanvas("c2","c2",0,0,800,800);
h1->Draw();
h3->Draw("same");
h3->SetLineColor(kRed);
TCanvas* c3 = new TCanvas("c3","c3",0,0,800,800);
h1->Draw();
TH1* h3Copy = h3->DrawCopy("same");
h3Copy->SetLineColor(kBlack);
}