Hi.
I am a final year student trying to make a plot for my project. I am using a macro which takes my histograms and makes a stack plot of them. The only thing I can’t seem to do is join up the points in the histogram with a line. Does anyone know of an easy way to do this?
[code]#include
#include
#include “Rtypes.h”
#include “TCanvas.h”
#include “TFile.h”
#include “TROOT.h”
#include “TH1F.h”
#include “TRandom.h”
#include
#include “TGraphErrors.h”
//change to your location and uncomment
#include “/epp/scratch/atlas/cb366/workdir/RootUtils/AtlasUtils.h”
#ifndef CINT
#include “/epp/scratch/atlas/cb366/workdir/RootUtils/AtlasStyle.C”
#endif
using namespace std;
//explained in supersimple
void PlotText(){
myText( 0.20,0.89,1,"#sqrt{s}= 8 TeV", 0.045);
myText( 0.37,0.87,1,"#intL dt = 20.3 fb^{-1}", 0.045);
ATLASWIP_LABEL(0.2,0.78);
//ATLASPRELIM_LABEL(0.2,0.78);
//ATLASFORAPP_LABEL(0.2,0.78);
}
void SimplePlot(){
//change to your location
#ifdef CINT
gROOT->LoadMacro("/epp/scratch/atlas/cb366/workdir/RootUtils/AtlasUtils.C");
gROOT->LoadMacro("/epp/scratch/atlas/cb366/workdir/RootUtils/rootlogon.C");
#endif
SetAtlasStyle();
//if this doesn’t work you can leave it uncommented initially, it just sets all the formatting to the default ATLAS settings
//this is now a vector of files for each of your background processes change all the dirs to your files
TFile* f[10];
f[0] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/zz_all.root"); Color_t wjetscol=kViolet-7;
f[1] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/wz_all.root"); Color_t tcol=kYellow-9;
f[2] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/ttbar_all.root"); Color_t zwtcol=kCyan-1;
f[3] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/ttbarv_all.root"); Color_t ttcol=kOrange-2;
f[4] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/ww_all.root"); Color_t tvcol=kGreen-6;
f[5] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/single_top_all.root"); Color_t diboscol=kViolet-8;
f[6] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/triboson_all.root"); Color_t triboscol=kPink+1;
f[7] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/w+jets_all.root"); Color_t wwcol=kBlue;
f[8] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/z_gamma_all.root"); Color_t zjetscol=kViolet-9;
f[9] = new TFile("/epp/scratch/atlas/cb366/workdir/Ana/IrvexAnalysis/histos/output/ISR_ThreeLep/sm_background/w_gamma_all.root"); Color_t mccol=kRed;
// set the colours and line attributes here
Color_t mylinecol[10] = { kViolet, kYellow, kCyan, kOrange, kGreen, kViolet-8, kPink, kBlue, /kBlack,/ kViolet, mccol};
Color_t myfillcol[10] = { wjetscol, tcol, zwtcol, ttcol, tvcol, diboscol, triboscol, wwcol, /vgcol,/ zjetscol, kGray+3};
Color_t myfillsty[10] = { 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, /1001,/ 1001, 3004};
Style_t mylinestyle[10] = { 1, 1, 1, 1, 1, 1, 1, 1, /* 1, / 1, 1};
Width_t mylinewidth[10] = { 2, 2, 2, 2, 2, 2, 2, 2, / 2,/ 2, 2};
Double_t mymarkersize[10] = { 0, 0, 0, 0, 0, 0, 0, 0, / 0,*/ 0, 0};
Double_t myxerrors[10] = {0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001};
Double_t myyerrors[10] = {0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001,0.00001};
//this is used for the legend formatting
TH1F* MyLine[10];
for( int i=0; i<10; i++){
TIter nextkey1( f[i]->GetListOfKeys()); TKey key1;
while( ( key1 = (TKey)nextkey1() ) ){
f[i]->cd();
TObject *obj = key1->ReadObj();
if (obj->IsA()->InheritsFrom(“TH1”)){
TH1 h1 = (TH1)obj;
h1->SetLineColor(mylinecol[i]); h1->SetMarkerColor(mylinecol[i]);
h1->SetLineStyle(mylinestyle[i]); h1->SetLineWidth(mylinewidth[i]);
h1->SetStats(kFALSE);
}
}
// this bit is useful for the legend
MyLine[i]=new TH1F("MyLine_"+i,"",7,-0.5,6.5); MyLine[i]->SetStats(kFALSE);
MyLine[i]->SetLineColor(mylinecol[i]); MyLine[i]->SetMarkerColor(mylinecol[i]);
MyLine[i]->SetLineStyle(mylinestyle[i]); MyLine[i]->SetLineWidth(mylinewidth[i]);
}
cout << “looped myline” << endl;
TLegend *legend = new TLegend(0.60,0.65,0.90,0.95);
legend->SetBorderSize(0);legend->SetTextFont(42);legend->SetTextSize(0.04);legend->SetFillColor(0);legend->SetLineColor(0);
//add entries for all the background processes, and total
legend->AddEntry(MyLine[9],“W Gamma”,“L”);
legend->AddEntry(MyLine[8],“Z Gamma”,“L”);
legend->AddEntry(MyLine[7],“W+ Jets”,“L”);
legend->AddEntry(MyLine[6],“Triboson”,“L”);
legend->AddEntry(MyLine[5],“Single Top”,“L”);
legend->AddEntry(MyLine[4],“WW”,“L”);
legend->AddEntry(MyLine[3],“ttbarv{t}”,“L”);
legend->AddEntry(MyLine[2],“ttbar{t} V”,“L”);
legend->AddEntry(MyLine[1],“WZ”,“L”);
legend->AddEntry(MyLine[0],“ZZ”,“L”);
//change to the cut name you have (pass_cosmic might be the last one after preselection?)
TString CUT[1]={“initial”};
//histos
TString HISTO[100]; double c1_ymin[9][100];double c1_ymax[9][100]; double c1_xmin[9][100];double c1_xmax[9][100];
for( int ic=0; ic<9; ic++ ){ for( int ih=0; ih<100; ih++ ){
c1_ymin[ic][ih]=0.01; // needs to be 0.1 for y on log scale
} }
cout << “Set plot parameters” << endl;
int myh=0;
// LepSum_Pt
HISTO[myh]=“LepSum_Pt”;
for(int ic=0; ic<2; ic++){ c1_xmin[ic][myh]=0; c1_xmax[ic][myh]=250; }
//c1_ymax[0][myh]=7;
//c1_ymax[1][myh]=20;
c1_ymax[0][myh]=100000;
c1_ymax[1][myh]=100000;
myh++;
//MET
HISTO[myh]=“MET”;
for(int ic=0; ic<2; ic++){ c1_xmin[ic][myh]=0; c1_xmax[ic][myh]=400; }
c1_ymax[0][myh]=100000;
c1_ymax[1][myh]=100000;
myh++;
// Bjet_Pt
HISTO[myh]=“Bjet_Pt”;
for(int ic=0; ic<2; ic++){ c1_xmin[ic][myh]=0; c1_xmax[ic][myh]=200; }
c1_ymax[0][myh]=100000;
c1_ymax[1][myh]=100000;
myh++;
// Jet_Pt
HISTO[myh]=“Jet_Pt”;
for(int ic=0; ic<2; ic++){ c1_xmin[ic][myh]=0; c1_xmax[ic][myh]=300; }
c1_ymax[0][myh]=100000;
c1_ymax[1][myh]=100000;
myh++;
// Elec1_Pt
HISTO[myh]=“Elec1_Pt”;
for(int ic=0; ic<2; ic++){ c1_xmin[ic][myh]=0; c1_xmax[ic][myh]=400; }
c1_ymax[0][myh]=100000;
c1_ymax[1][myh]=100000;
myh++;
// Muon2_Pt
HISTO[myh]=“Muon2_Pt”;
for(int ic=0; ic<2; ic++){ c1_xmin[ic][myh]=0; c1_xmax[ic][myh]=200; }
c1_ymax[0][myh]=100000;
c1_ymax[1][myh]=100000;
myh++;
// MLepLep
HISTO[myh]=“MLepLep”;
for(int ic=0; ic<2; ic++){ c1_xmin[ic][myh]=0; c1_xmax[ic][myh]=250; }
c1_ymax[0][myh]=100000;
c1_ymax[1][myh]=100000;
myh++;
// minMLepLep
HISTO[myh]=“minMLepLep”;
for(int ic=0; ic<2; ic++){ c1_xmin[ic][myh]=0; c1_xmax[ic][myh]=150; }
c1_ymax[0][myh]=100000;
c1_ymax[1][myh]=100000;
myh++;
// loop over cuts
for( int ic=0; ic<1; ic++ ){
// loop over histograms
for( int ih=0; ih<myh; ih++ ){
cout << ic << "\t" << ih << endl;
// make a canvas to plot on
//----------------------------------------------c1---------------------------------------------------------
TCanvas* c1 = new TCanvas("c1",HISTO[ih],800,600);
c1->cd();
c1->SetLogy();
c1->SetLineStyle(1);
c1->SetLineWidth(1);
string cut=CUT[ic]; string histo=HISTO[ih];
// stack the backgrounds nicely and draw
THStack* mystack_c1;
mystack_c1 = new THStack("mystack_c1","");
cout << "made stack" << endl;
for( int i=0; i<9; i++){
//cout << "this is a test " << HISTO[ih] << "_" << CUT[ic] << endl;
TH1F* stackelement=f[i]->Get(HISTO[ih]+"_"+CUT[ic]);
mystack_c1->Add(stackelement);
c1->cd();
mystack_c1->Draw("nostack");
//draw the total on top
if( i==8 ){
c1->cd(); mystack_c1->Draw("nostack");
mystack_c1->GetXaxis()->SetTitle(stackelement->GetXaxis()->GetTitle());
mystack_c1->GetYaxis()->SetTitle(stackelement->GetYaxis()->GetTitle());
}
}
cout << " done stacking" << endl;
legend->Draw();
PlotText();
//update and save
c1->cd(); c1->Update();
c1->Print("root/ChrisBarber_"+HISTO[ih]+"_"+CUT[ic]+".root");
c1->Print("gif/ChrisBarber_"+HISTO[ih]+"_"+CUT[ic]+".gif"); // it's helpful to put your name in the filename for later papers etc
cout << "saved gif" << endl;
c1->Print("eps/ChrisBarber_"+HISTO[ih]+"_"+CUT[ic]+".eps");
cout << "saved eps" << endl;
c1->Print("png/ChrisBarber_"+HISTO[ih]+"_"+CUT[ic]+".png");
cout << "saved png" << endl;
}
}
}
[/code]
Thanks,
Chris