Project

General

Profile

demo_plot.C

Macro to produce demo plot - Christopher Backhouse, 07/26/2013 02:59 PM

 
1
void demo_plot()
2
{
3
  TH1* mc = new TH1F("", ";Energy (GeV);Events", 20, 0, 6);
4
  TF1* f = new TF1("f", "TMath::Gaus((x-2.3)*2)", 0, 6);
5
  mc->Add(f, 20);
6
  mc->SetLineColor(kRed);
7
  TH1* mcerr = (TH1*)mc->Clone();
8
  mcerr->SetMarkerSize(0);
9
  mcerr->SetFillColor(kRed-9);
10

    
11
  for(int n = 0; n < mcerr->GetNbinsX()+2; ++n){
12
    mcerr->SetBinError(n, mcerr->GetBinContent(n)*.05);
13
  }
14

    
15
  TF1* ffit = new TF1("fit", "TMath::Gaus((x-2.3)*2)*(1+sin(1/x)**2)", 0, 6);
16

    
17
  TH1* hfit = new TH1F("", ";Reconstructed energy (GeV);Events", 20, 0, 6);
18
  hfit->Add(ffit, 20);
19

    
20
  TH1* hbkg = new TH1F("", ";Energy (GeV);Events", 20, 0, 6);
21
  hbkg->SetFillColor(kGray);
22
  hbkg->Add(f, 5);
23

    
24

    
25
  hfit->SetLineColor(kBlue);
26

    
27
  hfit->GetYaxis()->SetRangeUser(0, 35);
28
  CenterTitles(hfit);
29

    
30
  hfit->DrawClone();
31

    
32
  TLatex* sample = new TLatex(.5, .5, "SAMPLE");
33
  sample->SetTextAlign(22);
34
  sample->SetTextSize(.3);
35
  sample->SetTextAngle(30);
36
  sample->SetTextColor(18);
37
  sample->SetNDC();
38
  sample->Draw();
39

    
40
  mcerr->DrawClone("same e2");
41
  hfit->Draw("same");
42
  mc->DrawClone("hist same");
43
  hbkg->Draw("same");
44

    
45
  // For legend
46
  mc->SetFillColor(kRed-9);
47
  mc->SetFillStyle(1001);
48

    
49
  TH1* dat = new TH1F("", "", 20, 0, 6);
50
  dat->FillRandom("fit", 110);
51

    
52
  dat->Draw("ep same");
53

    
54
  TLegend* leg = new TLegend(.5, .55, .9, .85);
55
  leg->SetFillStyle(0);
56
  leg->AddEntry(dat, "Far detector data", "lep");
57
  leg->AddEntry(mc, "Unoscillated prediction", "lf");
58
  leg->AddEntry(hfit, "Best oscillation fit", "l");
59
  leg->AddEntry(hbkg, "NC background", "bf");
60
  leg->Draw();
61

    
62
  Preliminary();
63

    
64
  gPad->Print("demo.eps");
65
  gPad->Print("demo.png");
66
}