// a macro to read in xy data from a file and make a plot // First run root, then // .L drawXY.C // draw() #include "Riostream.h" void draw() { gROOT->Reset(); // first make a canvas and a 2D histogram for the axes TCanvas* canvas = new TCanvas("canvas", "canvas", 10, 10, 500, 500); canvas->SetFillColor(0); canvas->SetBorderMode(0); canvas->SetFrameBorderMode(0); // need this to turn off red hist frame! gROOT->SetStyle("Plain"); canvas->UseCurrentStyle(); gPad->SetLeftMargin(0.17); gPad->SetRightMargin(0.05); gPad->SetTopMargin(0.07); gPad->SetBottomMargin(0.17); gStyle->SetOptStat(0); gStyle->SetTitleBorderSize(0); gStyle->SetTitleSize(0.04); gStyle->SetTextFont(42); gStyle->SetTextSize(0.04); gStyle->SetTitleFont(42, "hxy"); // for histogram and axis title gStyle->SetLabelFont(42, "xyz"); // for axis labels (values) gStyle->SetTitleOffset(0.8, "h"); // what does this do? gStyle->SetTitleX(0.15); gStyle->SetTitleY(0.99); gROOT->ForceStyle(); // can make histogram or alternatively use the histograms automatically // connected to the TF1 or TGraph objects double xMin = 0.; double xMax = 1; double yMin = 0.; double yMax = 8.; TH2F* axhist = new TH2F("axhist", "title", 10, xMin, xMax, 10, yMin, yMax); axhist->SetTitle(""); axhist->SetXTitle("x_{cut}"); axhist->SetYTitle("expected discovery significance"); gPad->SetLogx(0); gPad->SetLogy(0); double u[20]; double x[20][500]; // Read in data from file and insert in TTree TString fileName; // cout << "Enter file name: "; // cin >> fileName; fileName = "sb.txt"; ifstream inFile; inFile.open(fileName); if (inFile.fail()) { cout << "Couldn't open file!" << endl; exit(1); } bool readLine = true; int lineNum = 0; int ncol; while ( readLine ){ TString line; stringstream ss; line.ReadLine(inFile); readLine = inFile.good(); if ( readLine ) { TString firstChar = line(0,1); bool useLine = firstChar != "#"; if ( useLine ){ int i = 0; stringstream ss; ss << line; // put whole line into ss TString token; bool getToken = true; while ( getToken ) { ss >> token; // extracts one token if ( token.Length() > 0 ) { u[i] = token.Atof(); i++; } else { getToken = false; } } // getToken ncol = i; for (int i=0; iGetXaxis(); TAxis* ya = axhist->GetYaxis(); xa->SetTitleOffset(1.2); // factor multiplies default offset ya->SetTitleOffset(1.4); xa->SetLabelOffset(0.005); ya->SetLabelOffset(0.02); xa->SetTickLength(0.015); // default = 0.03 ya->SetTickLength(0.015); // default = 0.03 xa->SetTitleSize(0.05); ya->SetTitleSize(0.05); // gPad->SetLogx(1); // xa->SetLimits(90., 700.); xa->SetNdivisions(5); // negative value should force number of divisions? ya->SetNdivisions(5); xa->SetLabelSize(0.05); ya->SetLabelSize(0.05); // Draw axes and then add stuff // kDot=1, kPlus, kStar, kCircle=4, kMultiply=5, // kFullDotSmall=6, kFullDotMedium=7, kFullDotLarge=8, // kFullCircle=20, kFullSquare=21, kFullTriangleUp=22, // kFullTriangleDown=23, kOpenCircle=24, kOpenSquare=25, // kOpenTriangleUp=26, kOpenDiamond=27, kOpenCross=28, // kFullStar=29, kOpenStar=30 axhist->Draw(); tg1->SetLineColor(kRed); tg1->SetLineWidth(2); tg1->SetLineStyle(2); tg1->SetMarkerColor(kRed); tg1->SetMarkerSize(0.8); tg1->SetMarkerStyle(20); tg1->Draw("L,same"); // or P for points tg2->SetLineColor(kBlue); tg2->SetLineWidth(2); tg2->SetLineStyle(1); tg2->SetMarkerColor(kBlue); tg2->SetMarkerSize(0.8); tg2->SetMarkerStyle(20); tg2->Draw("L,same"); // or P for points TLegend* leg = new TLegend(0.6, 0.71, 0.98, .89); // x1, y1, x2, y2 leg->SetTextFont(42); leg->SetTextSize(0.05); leg->SetBorderSize(0); leg->SetFillColor(0); leg->AddEntry(tg1, " s/#sqrt{b}", "l"); leg->AddEntry(tg2, " Z_{A}", "l"); leg->Draw(); TLatex* tl = new TLatex(); tl->SetTextAlign(11); tl->SetTextSize(0.05); tl->SetTextFont(42); tl->SetNDC(); // tl->DrawLatex(0.23, 0.82, "Fisher"); // tl->DrawLatex(.76, 0.33, "s = 2"); // tl->DrawLatex(.76, 0.465, "s = 5"); // tl->DrawLatex(.76, 0.6, "s = 10"); // tl->DrawLatex(.76, 0.73, "s = 20"); // Fix idiotic bug with legend overwriting frame TLine* lin = new TLine(); lin->SetLineWidth(1); lin->SetLineStyle(1); lin->SetLineColor(kBlack); lin->DrawLine(xMax, yMin, xMax, yMax); TPostScript psfile("medsig.eps", 113); // 113 makes eps canvas->Draw(); psfile.Close(); canvas->Print("medsig.gif", "gif"); }