예제 #1
0
void DrawGraph(string name, TGraphErrors* graph)
{
    TCanvas* canvas = new TCanvas(name.c_str(),"",1200,900);
    canvas->SetFillColor(kWhite);
    canvas->cd();
    TPad* pad = new TPad();
    // left right bottom top
    pad->SetMargin(0.15,0.05,0.15,0.05);
    pad->SetTicks(1,1);
    pad->SetFillColor(kWhite);
    pad->Draw();
    pad->cd();
    TGraphErrors* oldgraph = graph;
    graph = new TGraphErrors(*graph);
    delete oldgraph;
    float textsize = 0.055;
    graph->SetMinimum(0);
    graph->SetMaximum(100);
    graph->SetTitle("");
    graph->GetXaxis()->SetTitle("#it{m}(#it{K^{#plus}K^{#minus}}) [MeV/#it{c}^{2}]");
    graph->GetYaxis()->SetTitle("Efficiency [%]");
    graph->SetLineColor(kBlack);
    graph->SetLineWidth(1);
    graph->SetMarkerSize(1);
    graph->SetMarkerStyle(8);
    graph->SetMarkerColor(kBlack);
    graph->Draw("AP");
    graph->GetXaxis()->SetTitleSize(textsize*1.2);
    graph->GetYaxis()->SetTitleSize(textsize*1.2);
    graph->GetXaxis()->SetLabelSize(textsize);
    graph->GetYaxis()->SetLabelSize(textsize);
    graph->GetXaxis()->SetTitleFont(132);
    graph->GetYaxis()->SetTitleFont(132);
    graph->GetXaxis()->SetLabelFont(132);
    graph->GetYaxis()->SetLabelFont(132);
    graph->GetYaxis()->CenterTitle();
    double _blurbx        = 0.75;
    double _blurby        = 0.80;
    string _blurbtext     = "#splitline{LHCb}{#scale[0.75]{Preliminary}}";
    TLatex* _blurb = new TLatex(_blurbx,_blurby,_blurbtext.c_str());
    _blurb->SetTextFont(132);
    _blurb->SetTextColor(1);
    _blurb->SetNDC(kTRUE);
    _blurb->SetTextAlign(11);
    _blurb->SetTextSize(0.07);
    _blurb->Draw();
    canvas->SaveAs((name+".pdf").c_str());
    canvas->Write();
}
예제 #2
0
void RDK2AnalysisPlotter::makeEPGPlot(CoDet detType)
{
     gROOT->cd();
    TCanvas* theCanvas;
    TPad* mainPad;
    TPad* titlePad;
    TPad* gEPad;
    TPad* detPad;
    TPad* gEPadSubs[3];


    int numTitleLines=getTitleBoxLines( detType);
    int canvasNumPixelsYPlot=600;
    int canvasNumPixelsYPlots=2*canvasNumPixelsYPlot;
    int canvasNumPixelsYTitle=40*numTitleLines;
    int canvasNumPixelsY=canvasNumPixelsYPlots+canvasNumPixelsYTitle;

    theCanvas = new TCanvas("EPGExpMCAnalysisComparisonPlot","EPGExpMCAnalysisComparisonPlot",10,10,1200,canvasNumPixelsY);
     mainPad=(TPad*) theCanvas->GetPad(0);


    double ylow,yhigh;

    yhigh=1;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    titlePad=new TPad("titlePad", "titlePad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=ylow;
    ylow=ylow-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    gEPad=new TPad("gEPad", "gEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=ylow;
    ylow=0;
    detPad=new TPad("detPad", "detPad", 0., ylow, 1., yhigh, -1, 1, 1);

    titlePad->Draw();
    gEPad->Draw();
    detPad->Draw();



//    titlePad=(TPad*) theCanvas->GetPad(1);
//    gEPad=(TPad*) theCanvas->GetPad(2);
//    detPad=(TPad*) theCanvas->GetPad(3);
//    egTPad=(TPad*) theCanvas->GetPad(4);

    titlePad->SetMargin(0.05,0.0,0.0,0.0);
    gEPad->SetMargin(0.05,0.0,0.0,0.05);

    if(numExp>1 && numMC>1)
    {
        gEPad->Divide(2);

        gEPadSubs[0]=(TPad*) gEPad->GetPad(1);

        TPad* tempPad;
        tempPad=(TPad*) gEPad->GetPad(2);
        tempPad->Divide(1,2);
        gEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        gEPadSubs[2]=(TPad*) tempPad->GetPad(2);


        TPad* allBasePads[5]={titlePad,gEPadSubs[0],gEPadSubs[1],gEPadSubs[2],detPad};
         for (int i = 1;i< 5;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }

        gEPadSubs[2]->SetLogx();

        gEPadSubs[0]->SetMargin(0.15,0.1,.1,0.1);
        gEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        gEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);

        //Plot gE

        gEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_COMP);
        gEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_RESID);
        gEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_GEVAR,PLOT_NORMRESID);

    }
    else
    {

        TPad* allBasePads[3]={titlePad,gEPad,detPad};
        for (int i = 1;i< 3;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }

        gEPad->SetMargin(0.13,0.1,.1,0.1);


        //Plot gE

        gEPad->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_COMP);
    }
    mainPad->SetFillColor(kGray);

    ///Make Title box
    titlePad->cd();
    titlePad->SetFillColor(kGray);
    TPaveText* titleBox = makeTitleBox( detType);
    titleBox->Draw();

    detPad->SetMargin(0.1,0.05,.1,0.1);

    //Plot det
     detPad->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_DETS);

    TString coTypeString;
    if(detType==DET_EP)
    {
        coTypeString="EP";
    }
    else if(detType==DET_EPG)
    {
        coTypeString="EPG";
    }
    else if(detType==DET_EPBG)
    {
        coTypeString="EPBG";
    }
    TString imagePath=GRAPHS_DIR;
    imagePath+="layouts/PlotLayout";
    if(numMC) imagePath+="_MC";
    for (int i = 0;i< numMC;i++)
    {
        imagePath+=TString("_")+mc[i]->GetName();
    }
    if(numExp) imagePath+="_Exp";
    for (int i = 0;i< numExp;i++)
    {
        imagePath+=TString("_")+exp[i]->GetName();
    }

    imagePath+="_"+coTypeString+"_EPGPlots.pdf";
    theCanvas->SaveAs(imagePath);

    delete theCanvas;
    clearPlotHists();

}
예제 #3
0
void RDK2AnalysisPlotter::makeEPPlot(CoDet detType)
{
    gROOT->cd();
    TCanvas* theCanvas;
    TPad* mainPad;
    TPad* titlePad;
    TPad* pTPad;
    TPad* eEPad;
    TPad* pEPad;
    TPad* pTPadSubs[3];
    TPad* eEPadSubs[3];
    TPad* pEPadSubs[3];


    int numTitleLines=getTitleBoxLines( detType);
    int canvasNumPixelsYPlot=600;
    int canvasNumPixelsYPlots=3*canvasNumPixelsYPlot;
    int canvasNumPixelsYTitle=40*numTitleLines;
    int canvasNumPixelsY=canvasNumPixelsYPlots+canvasNumPixelsYTitle;

    theCanvas = new TCanvas("EPExpMCAnalysisComparisonPlot","EPExpMCAnalysisComparisonPlot",10,10,1200,canvasNumPixelsY);
     mainPad=(TPad*) theCanvas->GetPad(0);


    double ylow,yhigh;

    yhigh=1;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    titlePad=new TPad("titlePad", "titlePad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    pTPad=new TPad("pTPad", "pTPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY- 2*canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    eEPad=new TPad("eEPad", "eEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-2*canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    ylow=0;
    pEPad=new TPad("pEPad", "pEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    titlePad->Draw();
    pTPad->Draw();
    eEPad->Draw();
    pEPad->Draw();



//    titlePad=(TPad*) theCanvas->GetPad(1);
//    pTPad=(TPad*) theCanvas->GetPad(2);
//    eEPad=(TPad*) theCanvas->GetPad(3);
//    pEPad=(TPad*) theCanvas->GetPad(4);

    titlePad->SetMargin(0.05,0.0,0.0,0.0);
    pTPad->SetMargin(0.05,0.0,0.0,0.05);
    pEPad->SetMargin(0.05,0.0,0.0,0.05);
    eEPad->SetMargin(0.05,0.0,0.0,0.05);


    if(numExp+numMC >1)
    {
        pTPad->Divide(2);
        eEPad->Divide(2);
        pEPad->Divide(2);

        pTPadSubs[0]=(TPad*) pTPad->GetPad(1);
        eEPadSubs[0]=(TPad*) eEPad->GetPad(1);
        pEPadSubs[0]=(TPad*) pEPad->GetPad(1);

        TPad* tempPad;
        tempPad=(TPad*) pTPad->GetPad(2);
        tempPad->Divide(1,2);
        pTPadSubs[1]=(TPad*) tempPad->GetPad(1);
        pTPadSubs[2]=(TPad*) tempPad->GetPad(2);

        tempPad=(TPad*) pEPad->GetPad(2);
        tempPad->Divide(1,2);
        pEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        pEPadSubs[2]=(TPad*) tempPad->GetPad(2);

        tempPad=(TPad*) eEPad->GetPad(2);
        tempPad->Divide(1,2);
        eEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        eEPadSubs[2]=(TPad*) tempPad->GetPad(2);

        TPad* allBasePads[10]={titlePad,pTPadSubs[0],pTPadSubs[1],pTPadSubs[2],eEPadSubs[0],eEPadSubs[1],eEPadSubs[2],pEPadSubs[0],pEPadSubs[1],pEPadSubs[2]};
        for (int i = 1;i< 10;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }
        pTPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);
        pEPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);
        eEPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);

        pTPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        pEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        eEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);

        pTPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        pEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        eEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        //Plot pT

        pTPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_COMP);
        pTPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_RESID);
        pTPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_NORMRESID);


        //Plot eE
        eEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_COMP);
        eEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_RESID);
        eEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_NORMRESID);

        //Plot pE
        pEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_COMP);
        pEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_RESID);
        pEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_NORMRESID);
    }
    else
    {
        TPad* allBasePads[4]={titlePad,pTPad,eEPad,pEPad};
        for (int i = 1;i< 4;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }
        pTPad->SetMargin(0.13,0.1,.1,0.1);
        pEPad->SetMargin(0.13,0.1,.1,0.1);
        eEPad->SetMargin(0.13,0.1,.1,0.1);
        pTPad->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_COMP);
        eEPad->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_COMP);
        pEPad->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_COMP);

    }
    mainPad->SetFillColor(kGray);

    ///Make Title box
    titlePad->cd();
    titlePad->SetFillColor(kGray);
    TPaveText* titleBox = makeTitleBox( detType);
    titleBox->Draw();





    TString coTypeString;
    if(detType==DET_EP)
    {
        coTypeString="EP";
    }
    else if(detType==DET_EPG)
    {
        coTypeString="EPG";
    }
    else if(detType==DET_EPBG)
    {
        coTypeString="EPBG";
    }
     TString imagePath=GRAPHS_DIR;
    imagePath+="layouts/PlotLayout";
    if(numMC>0) imagePath+="_MC";
    for (int i = 0;i< numMC;i++)
    {
        imagePath+=TString("_")+mc[i]->GetName();
    }
    if(numExp>0) imagePath+="_Exp";
    for (int i = 0;i< numExp;i++)
    {
        imagePath+=TString("_")+exp[i]->GetName();
    }

    imagePath+="_"+coTypeString+"_EPPlots.pdf";
    theCanvas->SaveAs(imagePath);

    delete theCanvas;
    clearPlotHists();

}
예제 #4
0
파일: drawPlots.cpp 프로젝트: clare-b/VLQ
// *************************************** //
// this is a function that takes a set of  //
// histograms and draws them on a canvas   //
// in a stack, returning the canvas.       //
// It also plots the signal as a dashed    //
// line and the data with a ratio at the   //
// the bottom of data/allBackgrounds       //
//                                         //
// This one is supposed to make plots for  //
// the paper draft                         //
// *************************************** //
TCanvas* drawPlots::plotAll_VLQ_paperStyle(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, std::vector<TH1D*> signal, TH1D* data, TGraphAsymmErrors* err, bool doLogAxis, std::string extraTag){

   const unsigned int CANVAS_WIDTH  = 720;
   const unsigned int CANVAS_HEIGHT = 750;
   const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.75;
   const double RATIOPLOT_YAXIS_TITLE_SIZE   = 0.11;
   const double RATIOPLOT_YAXIS_LABEL_SIZE   = 0.09;  
   const double RATIOPLOT_XAXIS_TITLE_OFFSET = 1.6;
   const double RATIOPLOT_XAXIS_TITLE_SIZE   = 0.11;
   const double RATIOPLOT_XAXIS_LABEL_SIZE   = 0.09;
   
   TCanvas* canvas = new TCanvas("canvas","canvas",0,0,CANVAS_WIDTH,CANVAS_HEIGHT);
   
   canvas->SetMargin(0.,0.,0.,0.);
   canvas->Clear();
   //canvas->cd();
   
   SetAtlasStyle();
   gStyle->SetHistLineWidth(1.);
   gStyle->SetErrorX(0);

   err->SetLineColor(kWhite);
   err->SetLineWidth(0);

   // create histogram to store all backgrounds
   TH1D* allBackgrounds;
   bool gotSomething=false;
   for(int c=0; c<signal.size(); c++){
     if(signal[c]){
       allBackgrounds = (TH1D*)signal[c]->Clone("all_backgrounds");
       gotSomething=true;
     }
   }

   if(!gotSomething && data){
     allBackgrounds = (TH1D*)data->Clone("all_backgrounds");
     gotSomething=true;
   }
   if(!gotSomething){
     for(int b=0; b<histos.size(); b++){
       if(histos[b] && !gotSomething){
	 allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds");
	 gotSomething=true;
       }
     }
   }

   if(!gotSomething){
     std::cout << "Error: could not find any background, data, or signal for this plot" << std::endl;
     return canvas;
   }
   
   // set all bins to zero
   for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++)
     allBackgrounds->SetBinContent(i,0);

   // go through histos and combine the histograms that need to be combined
   // WZ stays separate, ttV stays separate, all others become "Other bkg"
   TH1D* otherBkgs=0; TH1D* ttbarX=0; TH1D* WZ_Sherpa=0;
   for(int cc=0; cc<histos.size(); cc++){
     if(histos[cc]){
       for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){
	 double binContent=allBackgrounds->GetBinContent(j)+histos[cc]->GetBinContent(j);
	 allBackgrounds->SetBinContent(j,binContent);
       }
       
       if(names[cc]=="ttbarX")
	 ttbarX=(TH1D*)histos[cc]->Clone("ttbarX_new");
       else if(names[cc]=="WZ_Sherpa")
	 WZ_Sherpa=(TH1D*)histos[cc]->Clone("WZ_new");
       else{

	 if(!otherBkgs)
	   otherBkgs=(TH1D*)histos[cc]->Clone("other_bkg_new");
	 else
	   otherBkgs->Add(histos[cc]);
       }
     }
   }

   // make stack of backgrounds, fill backgrounds histogram
   THStack* Stack = new THStack();
   if(ttbarX){
     ttbarX->SetLineColor(kGray);
     ttbarX->SetFillColor(kGray);
     Stack->Add(ttbarX);
   }
   if(WZ_Sherpa){
     WZ_Sherpa->SetLineColor(kBlue-9);
     WZ_Sherpa->SetFillColor(kBlue-9);
     Stack->Add(WZ_Sherpa);
   }
   if(otherBkgs){
     otherBkgs->SetLineColor(kOrange-2);
     otherBkgs->SetFillColor(kOrange-2);
     Stack->Add(otherBkgs);
   }

   TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio");

   // create main pad
   const double mainPad_ylow  = 0.3;
   const double mainPad_yhigh = 0.95;
   const double mainPad_xlow = 0.;
   const double mainPad_xhigh = 0.95;
   const double pad_margin_left = 0.2;
   const double pad_margin_right  = 0.02;
   double main_y_max = -99;
   double main_y_min = -99;

   TPad* mainPad = new TPad("main","main",mainPad_xlow,mainPad_ylow,mainPad_xhigh,mainPad_yhigh);
   mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top
   mainPad->Draw();
   mainPad->cd();

   // find max y
   if(allBackgrounds){
     int maxBinBkg = allBackgrounds->GetMaximumBin();
     double bkgYmax = allBackgrounds->GetBinContent(maxBinBkg);
     main_y_max = bkgYmax;
   }
   if(data){
     int maxBinData = data->GetMaximumBin();
     double dataYmax = data->GetBinContent(maxBinData);
     if(dataYmax > main_y_max) main_y_max = dataYmax;
   }
   if(main_y_max < .002) main_y_max = .1;

   if(doLogAxis){
     mainPad->SetLogy();
     main_y_min = 0.07;
     main_y_max*=60;
   }else{
     main_y_min = 0.001;
     main_y_max*=1.6;
   }

   // draw axis
   allBackgrounds->SetMaximum(main_y_max);
   allBackgrounds->SetMinimum(main_y_min);
   std::string title = std::string(";") + axisName + ";Events";
   std::stringstream binw; 
   
   binw<<allBackgrounds->GetBinWidth(1);
   std::string width = binw.str();
   if (axisName.find("GeV") != std::string::npos){
     width += " GeV";
     title += " / "+width;
   }
   allBackgrounds->SetTitle(title.c_str());   
   allBackgrounds->GetYaxis()->SetTitleOffset(1.4);
   allBackgrounds->GetYaxis()->SetTitleSize(0.06);
   allBackgrounds->GetXaxis()->SetTitleOffset(1.2);
   allBackgrounds->GetYaxis()->SetLabelSize(0.04);
   allBackgrounds->GetXaxis()->SetLabelSize(0.04);
   allBackgrounds->Draw("hist");

   // draw stack with error
   Stack->Draw("hist same");
   if(err){
     err->Draw("E2 same");
   }

   // make error histograms for the ratio plot
   TGraphAsymmErrors* ratioErr = tools::getRatio(err, backgroundsForRatio);

   // draw data
   if(data)
      data->Draw("e same");

   // draw signal
   if(signal[0]){
     signal[0]->SetLineStyle(2);
     signal[0]->SetLineColor(kRed+2);//kGreen+3 before
     signal[0]->SetLineWidth(5);
     signal[0]->Draw("hist same");
   }
   if(signal.size() > 1){
     if(signal[1]){
       //signal[1]->SetLineStyle(2);
       signal[1]->SetLineColor(kRed+2);
       signal[1]->SetLineWidth(4);
       signal[1]->Draw("hist same");
     }
     if(signal.size() > 2){
       if(signal[2]){
	 //signal[2]->SetLineStyle(2);
	 signal[2]->SetLineColor(kBlue+2);
	 signal[2]->SetLineWidth(4);
	 signal[2]->Draw("hist same");
       }
     }
   }
   allBackgrounds->Draw("axis same");

   // draw legend
   float leg_height = 0.3;
   float leg_width = 0.2;
   float leg_xoffset = 0.74;
   float leg_yoffset = 0.77;
   
   TLegend* leg = new TLegend(leg_xoffset,leg_yoffset-leg_height/2,leg_xoffset+leg_width,leg_yoffset+leg_height/2);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   leg->SetTextFont(52);
   leg->SetTextSize(0.033);
   
   // currently assuming first signal is Tbq (single T production), second is TTS, third is BBS
   leg->AddEntry(data, "data 2012");
   leg->AddEntry(otherBkgs, "Other bkg.", "f");
   leg->AddEntry(WZ_Sherpa, "WZ", "f");
   leg->AddEntry(ttbarX, "t#bar{t}+X", "f");
   if(signal.size()>1){
     if(signal[2])
       leg->AddEntry(signal[2], "B#bar{B} (650 GeV)", "l");
     if(signal[1])
       leg->AddEntry(signal[1], "T#bar{T} (650 GeV)", "l");
   }   
   if(signal[0])
     leg->AddEntry(signal[0], "T#bar{b}q (650 GeV)", "l");
   
   
   leg->AddEntry( err, "Uncertainty", "f");


   leg->Draw("lpe");
   
   ATLAS_LABEL(0.24,0.86,1);
   myText(0.36, 0.86, 1, .05, "Internal");
   char text[]="#sqrt{s}=8 TeV";
   myText(0.55,0.77,1,.04, text);
   char text_L[]="#int L dt = 20.3 fb^{-1}";
   myText(0.5, 0.84,1, .04, text_L);
   if(extraTag!=""){
     char tag_txt[extraTag.size()];
     strcpy(tag_txt, extraTag.c_str());
     if(extraTag.size()>15)
       myText(0.7, 0.56, 1, .04, tag_txt);
     else
       myText(0.75, 0.56, 1, .04, tag_txt);
   }
   char text_tri[]="Trilepton";
   myText(0.55, 0.70, 1, .04, text_tri);

   /*
   double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1);
   int t;
   char inText[100];
   if(back_int > 10000.)
     t=sprintf(inText, "N_{B} = %.3e", back_int);
   else
     t=sprintf(inText, "N_{B} = %.1f", back_int);
   myText(0.24, 0.6, 1, .04, inText);
   if(data)
     t=sprintf(inText, "N_{D} = %.0f", data->Integral(0,data->GetNbinsX()+1));
   else
     t=sprintf(inText, "N_{D} = %.0f", 0.);
   myText(0.24, 0.7, 1, .04, inText);
   */
   canvas->cd();
   
   // Draw Ratio plot
   // 1.6 and .4 are the normal ones
   double ratio_max = 3.2;
   double ratio_min = -.9;
  
   double pad_xlow = 0.;
   double pad_xhigh = 0.95;
   double pad_ylow = 0.0;
   double pad_yhigh = 0.3;
   
   const char* pad_name = "pad";
   TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh);

   pad4ratio->SetMargin(pad_margin_left,pad_margin_right,0.46,0.);
   pad4ratio->Draw();
   pad4ratio->cd();

   TH1D* ratioPlot;
   if(data)
     ratioPlot = (TH1D*)data->Clone("ratio");
   else if (signal[0]) 
     ratioPlot = (TH1D*)signal[0]->Clone("ratio"); // just for getting the axis
   else if (signal[1])
     ratioPlot = (TH1D*)signal[1]->Clone("ratio");
   else
     return canvas;

   ratioPlot->SetTitle("");
   ratioPlot->Divide(allBackgrounds);
   ratioPlot->GetYaxis()->SetTitle("Data / bkg");
   ratioPlot->GetXaxis()->SetTitle(axisName.c_str());

   if (data){
     
     // here change ratio_min and ratio_max if the ratio plot is quite flat
     double maxDeviation=0;
     double minDeviation=10.;
     double tempDev=0;
     for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){
       double binContent = ratioPlot->GetBinContent(ibin);
       tempDev=0;
       if(binContent>0 && binContent < 10) tempDev = std::abs(binContent-1.);
       if(tempDev > maxDeviation) maxDeviation = tempDev;
       if(tempDev < minDeviation) minDeviation = tempDev;
     }
     if(maxDeviation < 0.6){
       ratio_max = 1.6;
       ratio_min = 0.4;
     }
     else if(maxDeviation < 0.1){
       ratio_max = 1.12;
       ratio_min = 0.88;
     }
     else if(maxDeviation < 0.2){
       ratio_max = 1.25;
       ratio_min = .75;
     }
     if(minDeviation > 1.5){
       if(minDeviation > 2.)
	 ratio_max = 2.7;
       else
	 ratio_max = 2.2;
     }
     ratioPlot->SetMinimum(ratio_min);
     ratioPlot->SetMaximum(ratio_max);
   }     

   if(ratioPlot->GetXaxis()->GetNdivisions() > ratioPlot->GetNbinsX())
     ratioPlot->GetXaxis()->SetNdivisions(ratioPlot->GetNbinsX());
   if(ratioPlot->GetXaxis()->GetNdivisions() > 11)
     ratioPlot->GetXaxis()->SetNdivisions(11);
   ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE);
   ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE);
   ratioPlot->GetYaxis()->SetNdivisions(3);
   ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE);
   ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET);
   ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE);
   ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET);
   
   if(data){
     ratioPlot->Draw();
     // plot horizontal line at y=1
     TF1* horizontal = new TF1("horizontal","pol1",-10000,10000);
     horizontal->SetParameter(0,1.);
     horizontal->SetParameter(1,0.);
     horizontal->SetLineColor(kBlack);
     horizontal->SetLineStyle(2);
     horizontal->SetLineWidth(1);
     horizontal->Draw("same");
     ratioErr->Draw("E2 same");
   }else{ // there is no data
     ratioPlot->Draw("axis");
     char text[]="NO DATA";
     myText(0.4,0.6,1,.15,text);
   }
   
   return canvas;
}
예제 #5
0
파일: drawPlots.cpp 프로젝트: clare-b/VLQ
// *************************************** //
// this is a function that takes a set of  //
// histograms and draws them on a canvas   //
// in a stack, returning the canvas        //
// just for MC- no ratio and no data.      //
// This one includes syst and stat or just //
// stat errors                             //
// *************************************** //
TCanvas* drawPlots::plot_MC_noRatio_wError(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal, TH1D* errDown, TH1D* errUp){

   const unsigned int MAINPLOT_WIDTH  = 800;
   const unsigned int MAINPLOT_HEIGHT = 600;
   
   
   TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,MAINPLOT_HEIGHT);
   
   canvas->SetMargin(0.,0.,0.,0.);
   canvas->cd();
   
   double main_y_max = -99;
   double main_y_min = -99;
   double main_x_max = -99;
   double main_x_min = -99;
   for(int a=0; a<histos.size(); a++){
      GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max);
   }
   
   // create main pad
   TPad* mainPad = new TPad("main","main",0.,0.,1.,1.);
   mainPad->SetMargin(0.15,0.05,0.15,.05); // left, right, bottom, top
   mainPad->Draw();
   mainPad->cd();
   
   SetAtlasStyle();

   THStack* Stack = new THStack();
   std::string title = std::string(";") + axisName + ";Events";
   Stack->SetTitle(title.c_str());
   
   for(int b=0; b<histos.size(); b++){
      histos[b]->SetLineColor(1);
      histos[b]->SetFillColor(tools::setColor(names[b]));
      Stack->Add(histos[b]);
   }
   
   main_y_max = main_y_max*1.5;
   Stack->SetMaximum(main_y_max);
   Stack->Draw("hist");
   
   errDown->Draw("E2same");
   errUp->Draw("E2Same");
   
   signal->SetLineStyle(2);
   signal->SetLineColor(kRed);
   signal->Draw("hist same");
   
   TLegend* leg = new TLegend(0.7,0.7,0.93,0.9);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   leg->AddEntry(signal, "Signal", "f");
   for(int q=0; q<histos.size(); q++){
      leg->AddEntry(histos[q], names[q].c_str(), "f");
   }
   leg->Draw("lpe");
   
   ATLAS_LABEL(0.2,0.85,1);
   char text[]="#sqrt{s}=8 TeV";
   myText(0.2,0.7,1,text);
   
   return canvas;
}
예제 #6
0
파일: drawPlots.cpp 프로젝트: clare-b/VLQ
// *************************************** //
// this is a function that takes a set of  //
// histograms and draws them on a canvas   //
// in a stack, returning the canvas.       //
// It also plots the signal as a dashed    //
// line and the data with a ratio at the   //
// the bottom of data/allBackgrounds       //
//                                         //
// This one is supposed to match the plots //
// make by JP                              //
// *************************************** //
TCanvas* drawPlots::plotAll_VLQ(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, std::vector<TH1D*> signal, TH1D* data, TGraphAsymmErrors* err, bool isSignalRegion, bool doLogAxis, std::string channel){

   const unsigned int CANVAS_WIDTH  = 720;
   const unsigned int CANVAS_HEIGHT = 750;
   const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.75;
   const double RATIOPLOT_YAXIS_TITLE_SIZE   = 0.11;
   const double RATIOPLOT_YAXIS_LABEL_SIZE   = 0.09;  
   const double RATIOPLOT_XAXIS_TITLE_OFFSET = 1.6;
   const double RATIOPLOT_XAXIS_TITLE_SIZE   = 0.11;
   const double RATIOPLOT_XAXIS_LABEL_SIZE   = 0.09;
   
   TCanvas* canvas = new TCanvas("canvas","canvas",0,0,CANVAS_WIDTH,CANVAS_HEIGHT);
   
   canvas->SetMargin(0.,0.,0.,0.);
   canvas->Clear();
   canvas->cd();
   
   SetAtlasStyle();
   gStyle->SetHistLineWidth(1.);
   
   // create histogram to store all backgrounds
   TH1D* allBackgrounds;
   bool gotSomething=false;
   for(int c=0; c<signal.size(); c++){
     if(signal[c]){
       allBackgrounds = (TH1D*)signal[c]->Clone("all_backgrounds");
       gotSomething=true;
     }
   }
   if(!gotSomething && data)
     allBackgrounds = (TH1D*)data->Clone("all_backgrounds");
   if(!gotSomething){
     for(int b=0; b<histos.size(); b++){
       if(histos[b] && !gotSomething){
	 allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds");
	 gotSomething=true;
       }
     }
   }

   if(!gotSomething){
     std::cout << "Error: could not find any background, data, or signal for this plot" << std::endl;
     return canvas;
   }
   
   // set all bins to zero
   for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++)
     allBackgrounds->SetBinContent(i,0);
   
   // make stack of backgrounds, fill backgrounds histogram
   THStack* Stack = new THStack();
   for(int b=0; b<histos.size(); b++){
     if(histos[b]){
       if(histos[b]->GetEntries() > 0.){
	 histos[b]->SetLineColor(1);
	 histos[b]->SetFillColor(tools::setColor(names[b]));
	 Stack->Add(histos[b]);
	 for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){
	   double binContent=allBackgrounds->GetBinContent(j)+histos[b]->GetBinContent(j);
	   allBackgrounds->SetBinContent(j,binContent);
	 }
       }
     }
   } 
   TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio");

   // create main pad
   const double mainPad_ylow  = 0.3;
   const double mainPad_yhigh = 0.95;
   const double mainPad_xlow = 0.;
   const double mainPad_xhigh = 0.95;
   const double pad_margin_left = 0.2;
   const double pad_margin_right  = 0.02;
   double main_y_max = -99;
   double main_y_min = -99;

   TPad* mainPad = new TPad("main","main",mainPad_xlow,mainPad_ylow,mainPad_xhigh,mainPad_yhigh);
   mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top
   mainPad->Draw();
   mainPad->cd();

   // find max y
   if(allBackgrounds){
     int maxBinBkg = allBackgrounds->GetMaximumBin();
     double bkgYmax = allBackgrounds->GetBinContent(maxBinBkg);
     main_y_max = bkgYmax;
   }
   if(data){
     int maxBinData = data->GetMaximumBin();
     double dataYmax = data->GetBinContent(maxBinData);
     if(dataYmax > main_y_max) main_y_max = dataYmax;
   }
   if(main_y_max < .002) main_y_max = .1;

   if(doLogAxis){
     mainPad->SetLogy();
     main_y_min = 0.007;
     main_y_max*=600;
   }else{
     main_y_min = 0.001;
     main_y_max*=1.6;
   }

   // draw axis
   allBackgrounds->SetMaximum(main_y_max);
   allBackgrounds->SetMinimum(main_y_min);
   std::string title = std::string(";") + axisName + ";events/bin";
   allBackgrounds->SetTitle(title.c_str());   
   allBackgrounds->GetYaxis()->SetTitleOffset(1.4);
   allBackgrounds->GetYaxis()->SetTitleSize(0.06);
   allBackgrounds->GetXaxis()->SetTitleOffset(1.2);
   allBackgrounds->GetYaxis()->SetLabelSize(0.04);
   allBackgrounds->GetXaxis()->SetLabelSize(0.04);
   allBackgrounds->Draw("hist");

   // draw stack with error
   Stack->Draw("hist same");
   if(err){
     err->Draw("E2 same");
   }

   // make error histograms for the ratio plot
   TGraphAsymmErrors* ratioErr = tools::getRatio(err, backgroundsForRatio);

   // draw data
   if(!isSignalRegion && data)
      data->Draw("e same");

   // draw signal
   if(signal[0]){
     signal[0]->SetLineStyle(2);
     signal[0]->SetLineColor(kRed);
     signal[0]->SetLineWidth(5);
     signal[0]->Draw("hist same");
   }
   if(signal.size() > 1){
     if(signal[1]){
       signal[1]->SetLineStyle(2);
       signal[1]->SetLineColor(kOrange+7);
       signal[1]->SetLineWidth(4);
       signal[1]->Draw("hist same");
     }
     if(signal.size() > 2){
       if(signal[2]){
	 signal[2]->SetLineStyle(2);
	 signal[2]->SetLineColor(kPink-6);
	 signal[2]->SetLineWidth(4);
	 signal[2]->Draw("hist same");
       }
     }
   }
   allBackgrounds->Draw("axis same");

   // draw legend
   float leg_height = 0.45;
   float leg_width = 0.2;
   float leg_xoffset = 0.74;
   float leg_yoffset = 0.7;
   
   TLegend* leg = new TLegend(leg_xoffset,leg_yoffset-leg_height/2,leg_xoffset+leg_width,leg_yoffset+leg_height/2);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   leg->SetTextFont(52);
   leg->SetTextSize(0.033);
   
   // currently assuming first signal is Tbq (single T production), second is TTS, third is BBS
   if(signal[0])
     leg->AddEntry(signal[0], "Tbq (650 GeV)", "l");
   if(signal.size()>1){
     if(signal[1])
       leg->AddEntry(signal[1], "TT_{S} (650 GeV)", "l");
     if(signal[2])
       leg->AddEntry(signal[2], "BB_{S} (650 GeV)", "l");
   }
   if(!isSignalRegion)
     leg->AddEntry(data, "data 2012");
   for(int q=0; q<histos.size(); q++){
     if(histos[q]){
       if(histos[q]->GetEntries() > 0.)
	 leg->AddEntry(histos[q], plotLists::GetLegendName(names[q]).c_str(), "f");
     }
   }
   leg->Draw("lpe");
   
   ATLAS_LABEL(0.24,0.86,1);
   myText(0.36, 0.86, 1, .05, "Internal");
   char text[]="#sqrt{s}=8 TeV";
   myText(0.55,0.77,1,.04, text);
   char text_L[]="#int L dt = 20.3 fb^{-1}";
   myText(0.5, 0.84,1, .04, text_L);
   if(channel!=""){
     char chan_txt[channel.size()-1];
     strcpy(chan_txt, (channel.substr(1)).c_str());
     myText(0.5, 0.7, 1, .06, chan_txt);
   }
   char inText[100];
   int t;
   if(signal[0])
     t=sprintf(inText, "N_{Tbq} = %.1f", signal[0]->Integral(0,signal[0]->GetNbinsX()+1));
   else
     t=sprintf(inText, "N_{Tbq} = %.1f", 0.);
   myText(0.24, 0.7, 1, .04, inText);
   if(signal.size()>1){
     if(signal[1])
       t=sprintf(inText, "N_{TTS} = %.1f", signal[1]->Integral(0,signal[1]->GetNbinsX()+1));
     else
       t=sprintf(inText, "N_{TTS} = %.1f", 0.);
     myText(0.24, 0.65, 1, .04, inText);
     if(signal.size()>2){
       if(signal[2])
	 t=sprintf(inText, "N_{BBS} = %.1f", signal[2]->Integral(0,signal[2]->GetNbinsX()+1));
       else
	 t=sprintf(inText, "N_{BBS} = %.1f", 0.);
       myText(0.24, 0.6, 1, .04, inText);
     }
   }

   double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1);
   if(back_int > 10000.)
     t=sprintf(inText, "N_{B} = %.3e", back_int);
   else
     t=sprintf(inText, "N_{B} = %.1f", back_int);
   myText(0.24, 0.75, 1, .04, inText);
   if(!isSignalRegion){
     if(data)
       t=sprintf(inText, "N_{D} = %.0f", data->Integral(0,data->GetNbinsX()+1));
     else
       t=sprintf(inText, "N_{D} = %.0f", 0.);
     myText(0.24, 0.8, 1, .04, inText);
   }
   
   canvas->cd();
   
   // Draw Ratio plot
   double ratio_max = 1.6;
   double ratio_min = 0.4;
  
   double pad_xlow = 0.;
   double pad_xhigh = 0.95;
   double pad_ylow = 0.0;
   double pad_yhigh = 0.3;
   
   const char* pad_name = "pad";
   TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh);

   pad4ratio->SetMargin(pad_margin_left,pad_margin_right,0.46,0.);
   pad4ratio->Draw();
   pad4ratio->cd();

   TH1D* ratioPlot;
   if(data)
     ratioPlot = (TH1D*)data->Clone("ratio");
   else if (signal[0]) 
     ratioPlot = (TH1D*)signal[0]->Clone("ratio"); // just for getting the axis

   ratioPlot->SetTitle("");
   ratioPlot->Divide(allBackgrounds);
   ratioPlot->GetYaxis()->SetTitle("Data/MC");
   ratioPlot->GetXaxis()->SetTitle(axisName.c_str());

   if (data){
     // here change ratio_min and ratio_max if the ratio plot is quite flat
     double maxDeviation=0;
     double tempDev=0;
     for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){
       tempDev = std::abs(ratioPlot->GetBinContent(ibin)-1.);
       if(tempDev > maxDeviation) maxDeviation = tempDev;
     }
     if(maxDeviation < 0.1){
       ratio_max = 1.12;
       ratio_min = 0.88;
     }
     else if(maxDeviation < 0.2){
       ratio_max = 1.25;
       ratio_min = .75;
     }
     ratioPlot->SetMinimum(ratio_min);
     ratioPlot->SetMaximum(ratio_max);
   }     

   if(ratioPlot->GetXaxis()->GetNdivisions() > ratioPlot->GetNbinsX())
     ratioPlot->GetXaxis()->SetNdivisions(ratioPlot->GetNbinsX());
   if(ratioPlot->GetXaxis()->GetNdivisions() > 11)
     ratioPlot->GetXaxis()->SetNdivisions(11);
   ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE);
   ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE);
   ratioPlot->GetYaxis()->SetNdivisions(3);
   ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE);
   ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET);
   ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE);
   ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET);
   
   if(!isSignalRegion && data){
     ratioPlot->Draw();
     // plot horizontal line at y=1
     TF1* horizontal = new TF1("horizontal","pol1",-10000,10000);
     horizontal->SetParameter(0,1.);
     horizontal->SetParameter(1,0.);
     horizontal->SetLineColor(kBlack);
     horizontal->SetLineStyle(2);
     horizontal->SetLineWidth(1);
     horizontal->Draw("same");
     ratioErr->Draw("E2 same");
   }else if(isSignalRegion){
     ratioPlot->Draw("axis");
     char text[]="DATA IS BLIND HERE";
     myText(0.4,0.6,1,.15,text);
   }else{ // in this case it is not the signal region but there is no data
     ratioPlot->Draw("axis");
     char text[]="NO DATA";
     myText(0.4,0.6,1,.15,text);
   }
   
   return canvas;
}
예제 #7
0
파일: drawPlots.cpp 프로젝트: clare-b/VLQ
// *************************************** //
// this is a function that takes a set of  //
// histograms and draws them on a canvas   //
// in a stack, returning the canvas.       //
// It also plots the signal as a dashed    //
// line and the data with a ratio at the   //
// the bottom of data/allBackgrounds       //
// *************************************** //
TCanvas* drawPlots::plotAll(std::vector<TH1D*> histos, std::vector<std::string> names, std::string axisName, TH1D* signal, TH1D* data, TH1D* errDown, TH1D* errUp, bool isSignalRegion, bool doLogAxis){
         
   const unsigned int MAINPLOT_WIDTH  = 800;
   const unsigned int MAINPLOT_HEIGHT = 500;
   const unsigned int RATIOPLOT_HEIGHT = 125;
   const unsigned int OFFSET = 10;
   
  //LUKE: Title offset and title size are proportional in 
  //root, so you have to change them together, 
  //this makes me a sad panda 
   const double RATIOPLOT_YAXIS_TITLE_OFFSET = 0.4;
   const double RATIOPLOT_YAXIS_TITLE_SIZE   = 0.14;
   const double RATIOPLOT_YAXIS_TICK_LENGTH  = 0.01;
   const double RATIOPLOT_YAXIS_LABEL_SIZE   = 0.15;
  
   const double RATIOPLOT_XAXIS_TITLE_OFFSET = 0.9;
   const double RATIOPLOT_XAXIS_TITLE_SIZE   = 0.2;
   const double RATIOPLOT_XAXIS_TICK_LENGTH  = 0.05;
   const double RATIOPLOT_XAXIS_LABEL_SIZE   = 0.2;
   
   const double CANVAS_HEIGHT = MAINPLOT_HEIGHT+RATIOPLOT_HEIGHT+OFFSET;
   
   TCanvas* canvas = new TCanvas("canvas","canvas",0,0,MAINPLOT_WIDTH,CANVAS_HEIGHT);
   
   canvas->SetMargin(0.,0.,0.,0.);
   canvas->Clear();
   canvas->cd();
   
   // create main pad
   const double mainPad_ylow  = (CANVAS_HEIGHT - MAINPLOT_HEIGHT)/CANVAS_HEIGHT;
   const double mainPad_yhigh = 1.;
  
   const double pad_margin_left = 0.15;
   const double pad_margin_right  = 0.05;
   
   double main_y_max = -99;
   double main_y_min = -99;
   double main_x_max = -99;
   double main_x_min = -99;
   for(int a=0; a<histos.size(); a++){
     if(histos[a]){
       if(histos[a]->GetEntries()> 0.){
	 GetAxisLimits(histos[a], main_x_min, main_x_max, main_y_min, main_y_max);
       }
     }
   }
   
   if(data){
     int maxBinData = data->GetMaximumBin();
     double dataYmax = data->GetBinContent(maxBinData);
     if(dataYmax > main_y_max) main_y_max = dataYmax;
   }

   // create main pad
   TPad* mainPad = new TPad("main","main",0.,mainPad_ylow,1.,mainPad_yhigh);
   mainPad->SetMargin(pad_margin_left,pad_margin_right,0.,.05); // left, right, bottom, top
   mainPad->Draw();
   mainPad->cd();

   SetAtlasStyle();

   if(doLogAxis)mainPad->SetLogy();

   // clone signal or data because one should exist for each plot
   TH1D* allBackgrounds;
   bool gotSomething=false;
   if(signal)
     allBackgrounds = (TH1D*)signal->Clone("all_backgrounds");
   else if(data)
     allBackgrounds = (TH1D*)data->Clone("all_backgrounds");
   else{
     for(int b=0; b<histos.size(); b++){
       if(histos[b] && !gotSomething){
	 allBackgrounds = (TH1D*)histos[b]->Clone("all_backgrounds");
	 gotSomething=true;
       }
     }  
   }

   // set all bins to zero so that you can add all histograms to it
   for(int i=0; i<=allBackgrounds->GetNbinsX()+1; i++)
      allBackgrounds->SetBinContent(i,0);
   
   THStack* Stack = new THStack();
   std::string title = std::string(";") + axisName + ";Events";
   Stack->SetTitle(title.c_str());
   
   for(int b=0; b<histos.size(); b++){
     if(histos[b]){
       if(histos[b]->GetEntries() > 0.){
	 histos[b]->SetLineColor(1);
	 histos[b]->SetFillColor(tools::setColor(names[b]));
	 Stack->Add(histos[b]);
	 for(int j=0; j<=allBackgrounds->GetNbinsX()+1; j++){
	   double binContent=allBackgrounds->GetBinContent(j)+histos[b]->GetBinContent(j);
	   allBackgrounds->SetBinContent(j,binContent);
	 }
       }
     }
   }

   TH1D* backgroundsForRatio = (TH1D*)allBackgrounds->Clone("bkgds_for_ratio");
   
   if(doLogAxis){ 
     main_y_max = main_y_max*10;
     if(Stack->GetMinimum()>.1) Stack->SetMinimum(.1);
   }
   else main_y_max = main_y_max*1.4;
   Stack->SetMaximum(main_y_max);
   Stack->Draw("hist");
   errDown->Draw("E2same");
   errUp->Draw("E2Same");
   
   // make error histograms for the ratio plot
   TH1D* ratioErrDown = (TH1D*) errDown->Clone("ratio_error_down");
   TH1D* ratioErrUp = (TH1D*) errUp->Clone("ratio_error_up");

   ratioErrDown->Divide(backgroundsForRatio);
   ratioErrUp->Divide(backgroundsForRatio);

   if(!isSignalRegion && data)
      data->Draw("e same");

   if(signal){
     signal->SetLineStyle(2);
     signal->SetLineColor(kRed);
     signal->SetLineWidth(5);
     signal->Draw("hist same");
   }

   TLegend* leg = new TLegend(0.8,0.65,0.95,0.9);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   
   if(signal)
     leg->AddEntry(signal, "Signal", "l");
   if(!isSignalRegion)
     leg->AddEntry(data, "Data");
   for(int q=0; q<histos.size(); q++){
     if(histos[q]){
       if(histos[q]->GetEntries() > 0.)
	 leg->AddEntry(histos[q], names[q].c_str(), "f");
     }
   }
   leg->Draw("lpe");
   
   ATLAS_LABEL(0.2,0.85,1);
   char text[]="#sqrt{s}=8 TeV";
   myText(0.6,0.75,1,.04, text);
   char text_L[]="#int L dt = 20.3 fb^{-1}";
   myText(0.6, 0.85,1, .04, text_L);
   char inText[100];
   int t;
   if(signal)
     t=sprintf(inText, "N_{Signal} = %.1f", signal->Integral(0,signal->GetNbinsX()+1));
   else
     t=sprintf(inText, "N_{Signal} = %.1f", 0.);
   myText(0.2, 0.75, 1, .04, inText);
   double back_int = allBackgrounds->Integral(0,allBackgrounds->GetNbinsX()+1);
   if(back_int > 10000.)
     t=sprintf(inText, "N_{Bkgd} = %.3e", back_int);
   else
     t=sprintf(inText, "N_{Bkgd} = %.1f", back_int);
   myText(0.2, 0.7, 1, .04, inText);
   if(!isSignalRegion){
     if(data)
       t=sprintf(inText, "N_{Data} = %.0f", data->Integral(0,data->GetNbinsX()+1));
     else
       t=sprintf(inText, "N_{Data} = %.0f", 0.);
     myText(0.2, 0.65, 1, .04, inText);
   }
   
   canvas->cd();
   
   // Draw Ratio plot
   double ratio_max = 1.6;
   double ratio_min = 0.4;
  
   const double x_axis_size = 0.4;
   const double ratio_pad_height = RATIOPLOT_HEIGHT/CANVAS_HEIGHT;
   
   double pad_xlow = 0.,pad_xhigh = 1.;
   double pad_ylow = OFFSET/CANVAS_HEIGHT,pad_yhigh = ratio_pad_height;
   
   const char* pad_name = "pad";
   TPad* pad4ratio = new TPad(pad_name,pad_name,pad_xlow,pad_ylow,pad_xhigh,pad_yhigh);
   
   pad4ratio->SetMargin(pad_margin_left,pad_margin_right,x_axis_size,0.);
   pad4ratio->Draw();
   pad4ratio->cd();

   TH1D* ratioPlot;
   if(data) ratioPlot = (TH1D*)data->Clone("ratio");
   else if(signal) ratioPlot = (TH1D*)signal->Clone("ratio"); // if there is no data then use signal for axis 
   ratioPlot->SetTitle("");
   ratioPlot->GetYaxis()->SetTitle("Data/MC");
   ratioPlot->GetXaxis()->SetTitle(axisName.c_str());
   if(data){
     ratioPlot->Divide(allBackgrounds);
     // here change ratio_min and ratio_max if the ratio plot is quite flat
     double maxDeviation=0;
     double tempDev=0;
     for(int ibin=1; ibin<=allBackgrounds->GetNbinsX(); ibin++){
       tempDev = std::abs(ratioPlot->GetBinContent(ibin)-1.);
       if(tempDev > maxDeviation) maxDeviation = tempDev;
     }
     if(maxDeviation < 0.1){
       ratio_max = 1.12;
       ratio_min = 0.88;
     }
     else if(maxDeviation < 0.2){
       ratio_max = 1.25;
       ratio_min = .75;
     }
     ratioPlot->SetMinimum(ratio_min);
     ratioPlot->SetMaximum(ratio_max);
   }
   ratioPlot->GetXaxis()->SetLabelSize(RATIOPLOT_XAXIS_LABEL_SIZE);
   ratioPlot->GetXaxis()->SetTickLength(RATIOPLOT_XAXIS_TICK_LENGTH);
   ratioPlot->GetYaxis()->SetLabelSize(RATIOPLOT_YAXIS_LABEL_SIZE);
   ratioPlot->GetYaxis()->SetTickLength(RATIOPLOT_YAXIS_TICK_LENGTH);
   ratioPlot->GetYaxis()->SetNdivisions(3);
   ratioPlot->GetYaxis()->SetTitleSize(RATIOPLOT_YAXIS_TITLE_SIZE);
   ratioPlot->GetYaxis()->SetTitleOffset(RATIOPLOT_YAXIS_TITLE_OFFSET);
   ratioPlot->GetXaxis()->SetTitleSize(RATIOPLOT_XAXIS_TITLE_SIZE);
   ratioPlot->GetXaxis()->SetTitleOffset(RATIOPLOT_XAXIS_TITLE_OFFSET);
   
   if(!isSignalRegion && data){
     ratioPlot->Draw();
     // plot horizontal line at y=1
     TF1* horizontal = new TF1("horizontal","pol1",-10000,10000);
     horizontal->SetParameter(0,1.);
     horizontal->SetParameter(1,0.);
     horizontal->SetLineColor(kBlack);
     horizontal->SetLineStyle(2);
     horizontal->SetLineWidth(1);
     horizontal->Draw("same");
     ratioErrDown->Draw("E2same");
     ratioErrUp->Draw("E2same");
   }else if(isSignalRegion){
     ratioPlot->Draw("axis");
     char text[]="DATA IS BLINDED HERE";
     myText(0.4,0.6,1,.2,text);
   }else{ // in this case it is not the signal region but there is no data
     ratioPlot->Draw("axis");
     char text[]="NO DATA";
     myText(0.4,0.6,1,.2,text);
     }
   
   return canvas;
}
예제 #8
0
파일: drawPlots.cpp 프로젝트: clare-b/VLQ
// *************************************** //
// this is a function that draws all       //
// backrounds as a grey area, and compares //
// the shape of the backgrounds to that of //
// the signal                              //
// This one is supposed to match the plots //
// make by JP (Fig 3 of CONF note)         //
// *************************************** //
TCanvas* drawPlots::plotShape_VLQ(TH1D* bkgd, std::string axisName, std::vector<TH1D*> signal, bool doLogAxis, std::string channel){

  // only drawing shapes so normalize histograms
  std::cout << "background integral: " << bkgd->Integral() << std::endl;
  bkgd->Scale(1./bkgd->Integral());
  for(int ahist=0; ahist<signal.size(); ahist++){
    if(signal[ahist]){
      std::cout << "scaling signal: " << ahist << " with integral: " << signal[ahist]->Integral() << std::endl;
      signal[ahist]->Scale(1./signal[ahist]->Integral());
    }
  }

   const unsigned int CANVAS_WIDTH  = 720;
   const unsigned int CANVAS_HEIGHT = 750;
   TCanvas* canvas = new TCanvas("canvas","canvas",0,0,CANVAS_WIDTH,CANVAS_HEIGHT);
   
   canvas->SetMargin(0.,0.,0.,0.);
   canvas->Clear();
   canvas->cd();

   SetAtlasStyle();
   gStyle->SetHistLineWidth(1.);

   
   // create main pad
   const double mainPad_ylow  = 0.;
   const double mainPad_yhigh = 1.;
   const double mainPad_xlow = 0.;
   const double mainPad_xhigh = 1.;
   const double pad_margin_left = 0.16;
   const double pad_margin_right  = 0.035;
   
   double main_y_max = -99;
   double main_y_min = -99;

   TPad* mainPad = new TPad("main","main",mainPad_xlow,mainPad_ylow,mainPad_xhigh,mainPad_yhigh);
   mainPad->SetMargin(pad_margin_left,pad_margin_right,0.16,.05); // left, right, bottom, top
   mainPad->Draw();
   mainPad->cd();

   // find max y
   int maxBinBkg = bkgd->GetMaximumBin();
   double bkgYmax = bkgd->GetBinContent(maxBinBkg);
   main_y_max = bkgYmax;
   //   std::cout << "background maximum: " << bkgYmax << std::endl;
   if(main_y_max < .002) main_y_max = .1;
   
   if(doLogAxis){
     mainPad->SetLogy();
     main_y_min = 0.0001;
     main_y_max*=500;
   }else{
     main_y_min = 0.00001;
     main_y_max*=1.6;
   }

   // draw axis
   bkgd->SetMaximum(main_y_max);
   bkgd->SetMinimum(main_y_min);
   std::string title = std::string(";") + axisName + ";Fraction of events";
   std::stringstream binw; 
   binw<<bkgd->GetBinWidth(1);
   std::string width = binw.str();
   if (axisName.find("GeV") != std::string::npos) width += " GeV";
   if(bkgd->GetBinWidth(1) != 1) title += " / "+width;
   bkgd->SetTitle(title.c_str());   
   bkgd->GetYaxis()->SetTitleOffset(1.6);
   bkgd->GetXaxis()->SetTitleOffset(1.2);
   bkgd->GetYaxis()->SetLabelSize(0.03);
   bkgd->GetYaxis()->SetTitleSize(0.045);
   bkgd->GetXaxis()->SetTitleSize(0.045);
   bkgd->GetXaxis()->SetLabelSize(0.03);
   bkgd->SetFillStyle(3354);
   bkgd->SetFillColor(kGray+2);
   bkgd->SetLineColor(kGray+2);
   bkgd->Draw("histf");

   // draw signal
   if(signal[0]){
     std::cout << "printing Tbq" << std::endl;
     signal[0]->SetLineStyle(2);
     signal[0]->SetLineColor(kRed+2); // kGreen+3 was being used before
     signal[0]->SetLineWidth(5);
     signal[0]->Draw("hist same");
   }
   if(signal.size() > 1){
     if(signal[1]){
       std::cout << "printing TTS" << std::endl;
       //   signal[1]->SetLineStyle(2);
       signal[1]->SetLineColor(kRed+2);
       signal[1]->SetLineWidth(4);
       signal[1]->Draw("hist same");
     }
     if(signal.size() > 2){
       if(signal[2]){
	 std::cout << "printing BBS" << std::endl;
	 //	 signal[2]->SetLineStyle(2);
	 signal[2]->SetLineColor(kBlue+2);
	 signal[2]->SetLineWidth(4);
	 signal[2]->Draw("hist same");
       }
     }
   }
   bkgd->Draw("axis same");

   // draw legend
   float leg_height = 0.2;
   float leg_width = 0.4;
   float leg_xoffset = 0.65;
   float leg_yoffset = 0.8;
   
   TLegend* leg = new TLegend(leg_xoffset,leg_yoffset-leg_height/2,leg_xoffset+leg_width,leg_yoffset+leg_height/2);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   leg->SetBorderSize(0);
   leg->SetTextFont(72);
   leg->SetTextSize(0.026);
   
   // currently assuming first signal is single T, second is TTS
   leg->AddEntry(bkgd,"Background", "f");
   if(signal.size()>1){
     if(signal.size()>2){
       if(signal[2])
	 leg->AddEntry(signal[2], "B#bar{B} (650 GeV)", "l");
     }
     if(signal[1])
       leg->AddEntry(signal[1], "T#bar{T} (650 GeV)", "l");
   }  
   if(signal[0])
     leg->AddEntry(signal[0], "T#bar{b}q (650 GeV)", "l");
   
   leg->Draw("lpe");
   
   ATLAS_LABEL(0.24,0.86,1);
   myText(0.26, 0.81, 1, .04, "Internal");
   char text[]="#sqrt{s}=8 TeV";
   myText(0.48,0.82,1,.03, text);
   char text_L[]="Simulation";
   myText(0.47, 0.87,1, .03, text_L);
   char text_tri[]="Trilepton";
   myText(0.485, 0.77, 1, .03, text_tri);
   if(channel!=""){
     char chan_txt[channel.size()-1];
     strcpy(chan_txt, (channel.substr(1)).c_str());
     if(channel.size()>10)
       myText(0.55, 0.56, 1, .03, chan_txt);
     else
       myText(0.65, 0.56, 1, .03, chan_txt);
   }
   canvas->cd();
   
   return canvas;
}
//------------------------------------
//function to fit energy distributions
energyRes* get_res(int snum, Double_t energy, bool do_pion, bool use_f_pion, bool do_fit, bool do_show, bool do_print=false, bool do_batch=false){
	Sample* sp = sample_map[snum];
	if(!sp) { std::cout << "Sample " << snum << " is not loaded." << std::endl; energyRes* theRes = new energyRes(0,0); return theRes; }
	
	//select correct file
	std::string fpre = sp->fpre;
	if(do_pion) fpre += "_pion";
	else fpre += "_elec";

	//make filenames
	std::stringstream drawname, fname, piname;
	fname << sp->dir << "/" << fpre << "_" << energy << "gev_10k.root";
	if(do_pion) piname << "#pi^{-} " << energy << " GeV";
	else piname << "e^{-} " << energy << " GeV";

	//open file and tree
	TFile* _file;
	_file = TFile::Open((fname.str()).c_str());
	TTree* totalTree = (TTree*)_file->Get("Total");

	//default histo settings
	//double Emin = 0.1*energies[num]; //lower cut to remove weird peaks near E=zero
	double Emin = 0;
	double Emax = 2*energy;
	int nbins = 100;
	
	//ecal & hcal energies need to be calibrated
	get_sampling_factors(snum);

	//make tree drawing expressions
	//define mip as ecal < 1 gev = 1000 mev
	if(use_f_pion) drawname << sp->sam_pion;
	else drawname << sp->sam_elec;
	
	if(sp->det==Hcal) drawname << "*(hcal+" << sp->zeroWt << "*zero)/1000";
	else drawname << "*ecal/1000";

	drawname << ">>htemp(" << nbins << "," << Emin << "," << Emax << ")";
	//std::cout << drawname.str() << std::endl;

	TH1F* h_res; //to store histos drawn from tree
	TF1* gfit;
	TF1* gsnL;
	TF1* gsnR;

	//plotting variables
	TCanvas* can;
	TPad* pad;
	TLegend* leg;
	TPaveText* pave;
	TPaveText* pave_par;
	TLine *aLline;
	TLine *aRline;

	//create instance of energyRes object
	energyRes* theRes = new energyRes(energy,2);

	//draw w/ appropriate cut
	totalTree->Draw((drawname.str()).c_str(),"","hist goff");
	h_res = (TH1F*)gDirectory->Get("htemp");
	h_res->SetTitle("");
	h_res->GetXaxis()->SetTitle("Energy [GeV]");
	h_res->SetLineWidth(2);
	h_res->SetLineColor(kBlack);

	//names
	std::string ofit;
	if(do_fit) ofit = "fit";
	else ofit = "nofit";
	std::stringstream oname;
	oname << pdir << "/" << fpre;
	if(use_f_pion) oname << "_fpion";
	oname << "_response_" << ofit << "_" << energy << "gev";
	
	//get values from histo
	Double_t m = h_res->GetMean();
	Double_t me = h_res->GetMeanError();
	//Double_t m = h_res->GetBinCenter(h_res->GetMaximumBin()); //peak
	Double_t s = h_res->GetRMS();
	Double_t se = h_res->GetRMSError();
	Int_t N = h_res->GetEntries();
	
	std::vector<Double_t> stats(3,0);
	std::vector<Double_t> stat_err(3,0);
	stats[0] = N;
	stat_err[0] = 0;
	stats[1] = m;
	stat_err[1] = me;
	stats[2] = s;
	stat_err[2] = se;

	//find peak
	TSpectrum *spec = new TSpectrum(5);
	if(nbins < 100) spec->Search(h_res,6,"nobackground nodraw goff"); //turn off background removal when nbins too small
	else spec->Search(h_res,6,"nodraw goff");
	Float_t* xpos = spec->GetPositionX();
	Float_t* ypos = spec->GetPositionY();
	Double_t p = xpos[0];
	Double_t ph = ypos[0];
	if(do_show) std::cout << "peak: " << p << std::endl;
	
	//setup fitting function & do fit
	if (do_fit){
		gfit = new TF1("resp","gaus",0,h_res->GetXaxis()->GetXmax());
		//if(do_jet){
		//	gfit->SetParameters(ph,p,s);
		//	if(m > p) gfit->SetRange(p-1.5*s,p+1.0*s); //high tail
		//	else gfit->SetRange(p-1.0*s,p+1.5*s); //low tail
		//}
		//else{
			gfit->SetParameters((Double_t)N,m,s);
			gfit->SetRange(m-2*s,m+1*s); //fit within 2 std devs
			//if(m > p) gfit->SetRange(p-2*s,p+1*s); //high tail
			//else gfit->SetRange(p-1*s,p+2*s); //low tail
		//}
		
		//formatting
		gfit->SetLineColor(kRed);
		gfit->SetMarkerColor(kRed);
		gfit->SetLineWidth(2);
		//fit
		h_res->Fit(gfit,"LNQR");
	}
	
	//store parameters
	theRes->setStats(stats,stat_err);
	if(do_fit) theRes->setFit(gfit);
	//store histo
	h_res->SetDirectory(0);
	theRes->setHist(h_res);
	
	std::stringstream muname, signame, musigname, aLname, nLname, aRname, nRname, Nname, chiname;
	muname.precision(2);
	signame.precision(2);
	musigname.precision(3);
	aLname.precision(2);
	nLname.precision(2);
	aRname.precision(2);
	nRname.precision(2);
	chiname.precision(5);
	if (do_fit) {
		muname << fixed << "#mu = " << gfit->GetParameter(1) << " #pm " << gfit->GetParError(1);
		signame << fixed << "#sigma = " << gfit->GetParameter(2) << " #pm " << gfit->GetParError(2);
		musigname << fixed << "#sigma/#mu = " << gfit->GetParameter(2)/gfit->GetParameter(1) << " #pm " << 
		gfit->GetParameter(2)/gfit->GetParameter(1) * sqrt( Power(gfit->GetParError(1),2)/Power(gfit->GetParameter(1),2) +  Power(gfit->GetParError(2),2)/Power(gfit->GetParameter(2),2) );
		//aLname << fixed << "a_{L} = " << gfit->GetParameter(3) << " #pm " << gfit->GetParError(3);
		//nLname << fixed << "n_{L} = " << gfit->GetParameter(4) << " #pm " << gfit->GetParError(4);
		//aRname << fixed << "a_{R} = " << gfit->GetParameter(5) << " #pm " << gfit->GetParError(5);
		//nRname << fixed << "n_{R} = " << gfit->GetParameter(6) << " #pm " << gfit->GetParError(6);
		chiname << fixed << "#chi^{2}/ndf = " << gfit->GetChisquare()/gfit->GetNDF();
	}
	else {
		muname << fixed << "Mean = " << m << " #pm " << me;
		signame << fixed << "RMS = " << s << " #pm " << se;
		musigname << fixed << "RMS/Mean = " << s/m << " #pm " << s/m*sqrt((me*me)/(m*m)+(se*se)/(s*s));
	}
	Nname << "N = " << N; 

	//plotting
	if (do_show){
		can = new TCanvas((oname.str()).c_str(),(oname.str()).c_str(),700,500);
		can->cd();
		pad = new TPad("graph","",0,0,1,1);
		pad->SetMargin(0.12,0.05,0.15,0.05);
		pad->Draw();
		pad->cd();
		
		//formatting
		h_res->SetStats(kTRUE);
		gStyle->SetOptStat("mr");
		h_res->GetYaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC()));
		h_res->GetYaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC()));
		h_res->GetXaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC()));
		h_res->GetXaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC()));
		h_res->GetYaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC()));
		h_res->GetXaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC()));
		
		//plot histo and fit
		h_res->Draw("hist");
		if(do_fit) gfit->Draw("same");	
	
		//determine placing of legend and paves - par pave goes on side with more space
		Double_t xmin;
		if (m/((h_res->GetXaxis()->GetXmax() + h_res->GetXaxis()->GetXmin())/2) < 1) xmin = 0.65;
		else xmin = 0.2;
	
		if(do_fit) { //legend
			leg = new TLegend(xmin,0.78,xmin+0.2,0.88);
			leg->AddEntry(h_res,"Standalone");
			leg->AddEntry(gfit,"Fit");
			leg->SetFillColor(0);
			leg->SetBorderSize(0);
			leg->SetTextSize(0.05);
			leg->SetTextFont(42);
			leg->Draw("same");
			
			can->Update();
			/*
			//left line
			Double_t bndL = gfit->GetParameter(1) - gfit->GetParameter(2)*gfit->GetParameter(3);
			aLline = new TLine(bndL,pad->GetUymin(),bndL,pad->GetUymax());
			aLline->SetLineStyle(2);
			aLline->SetLineWidth(3);
			aLline->SetLineColor(kBlue);
			aLline->Draw("same");
			
			//left gaussian
			gsnL = new TF1("gsn","gaus",Emin,bndL);
			gsnL->SetParameters(gfit->GetParameter(0),gfit->GetParameter(1),gfit->GetParameter(2));
			gsnL->SetLineColor(kRed);
			gsnL->SetMarkerColor(kRed);
			gsnL->SetLineWidth(2);
			gsnL->SetLineStyle(2);
			gsnL->Draw("same");

			//line
			Double_t bndR = gfit->GetParameter(1) + gfit->GetParameter(2)*gfit->GetParameter(5);
			aRline = new TLine(bndR,pad->GetUymin(),bndR,pad->GetUymax());
			aRline->SetLineStyle(2);
			aRline->SetLineWidth(3);
			aRline->SetLineColor(kBlue);
			aRline->Draw("same");
			
			//right gaussian
			gsnR = new TF1("gsn","gaus",bndR,Emax);
			gsnR->SetParameters(gfit->GetParameter(0),gfit->GetParameter(1),gfit->GetParameter(2));
			gsnR->SetLineColor(kRed);
			gsnR->SetMarkerColor(kRed);
			gsnR->SetLineWidth(2);
			gsnR->SetLineStyle(2);
			gsnR->Draw("same");			
			*/
		}
		
		//pave
		pave = new TPaveText(xmin,0.68,xmin+0.2,0.78,"NDC");
		pave->AddText(sp->name.c_str());
		pave->AddText((piname.str()).c_str());
		pave->SetFillColor(0);
		pave->SetBorderSize(0);
		pave->SetTextFont(42);
		pave->SetTextSize(0.05);
		pave->Draw("same");

		//par pave
		Double_t ymin1;
		//if(do_fit) ymin1 = 0.26;
		//else ymin1 = 0.51;
		ymin1 = 0.47;
		pave_par = new TPaveText(xmin,ymin1,xmin+0.2,ymin1+0.05*4,"NDC");
		pave_par->AddText((Nname.str()).c_str());
		pave_par->AddText((muname.str()).c_str());
		pave_par->AddText((signame.str()).c_str());
		pave_par->AddText((musigname.str()).c_str());
		//if(do_fit){
		//	pave_par->AddText((aLname.str()).c_str());
		//	pave_par->AddText((nLname.str()).c_str());
		//	pave_par->AddText((aRname.str()).c_str());
		//	pave_par->AddText((nRname.str()).c_str());
		//	pave_par->AddText((chiname.str()).c_str());
		//}
		pave_par->SetFillColor(0);
		pave_par->SetBorderSize(0);
		pave_par->SetTextFont(42);
		pave_par->SetTextSize(0.05);
		pave_par->Draw("same");
		
		std::cout << "response:" << std::endl;
		
		std::cout << Nname.str() << std::endl;
		std::cout << muname.str() << std::endl;
		std::cout << signame.str() << std::endl;
		std::cout << musigname.str() << std::endl;
		if(do_fit){
		//	std::cout << "aL = " << gfit->GetParameter(3) << " +/- " << gfit->GetParError(3) << std::endl;
		//	std::cout << "nL = " << gfit->GetParameter(4) << " +/- " << gfit->GetParError(4) << std::endl;
		//	std::cout << "aR = " << gfit->GetParameter(5) << " +/- " << gfit->GetParError(5) << std::endl;
		//	std::cout << "nR = " << gfit->GetParameter(6) << " +/- " << gfit->GetParError(6) << std::endl;
			std::cout << "chi^2/ndf = " << gfit->GetChisquare()/gfit->GetNDF() << std::endl;
		}
		
		if(do_print) can->Print((oname.str()+"."+pformat).c_str(),pformat.c_str());
		if(do_batch) _file->Close();
	}
	else { _file->Close(); }
	
	//return data structure with relevant info
	return theRes;
}
예제 #10
0
//--------------------------------------
//function to calculate sampling factors
std::pair<Double_t,Double_t> g4_sample(int snum, Double_t energy, bool do_pion, bool do_show, bool do_print=false, bool set_val=true){
	Sample* sp = sample_map[snum];
	if(!sp) { std::cout << "Sample " << snum << " is not loaded." << std::endl; return std::pair<Double_t,Double_t>(0.,0.); }

	//select correct file
	std::string fpre = sp->fpre;
	if(do_pion) fpre += "_pion";
	else fpre += "_elec";

	//make filenames
	std::stringstream drawname, fname, piname;
	fname << sp->dir << "/" << fpre << "_" << energy << "gev_10k.root";
	if(do_pion) piname << "#pi^{-} " << energy << " GeV";
	else piname << "e^{-} " << energy << " GeV";

	//open file and tree
	TFile* _file;
	_file = TFile::Open((fname.str()).c_str());
	TTree* totalTree = (TTree*)_file->Get("Total");

	//get histo from tree (no display)
	//define mip as sam_ecal*ecal < 1 gev = 1000 mev (for pions in HCAL)
	if(sp->det==Hcal) drawname << "(hcal+" << sp->zeroWt << "*zero)/1000>>hsam(200)";
	else drawname << "(ecal)/1000>>hsam(200)";
	
	totalTree->Draw((drawname.str()).c_str(),"","hist goff");
	TH1F* hsam = (TH1F*)gDirectory->Get("hsam");
	
	//use parameters from histo to start fit
	TSpectrum* spec = new TSpectrum(5);
	spec->Search(hsam,5,"nodraw goff");
	Float_t* xpos = spec->GetPositionX();
	Float_t* ypos = spec->GetPositionY();

	Double_t m = xpos[0];
	Double_t me = hsam->GetMeanError();
	Double_t N = hsam->GetEntries();
	std::stringstream s_mean;
	s_mean.precision(3);
	Double_t f = energy/m;
	Double_t f_err = energy*(me/(m*m));
	s_mean << f << " #pm " << f_err;

	TPolyMarker* pm = new TPolyMarker(1, xpos, ypos);
	hsam->GetListOfFunctions()->Add(pm);
	pm->SetMarkerStyle(23);
	pm->SetMarkerColor(kRed);
	pm->SetMarkerSize(1.3);

	std::cout.precision(6);
	std::cout << "f_" << (do_pion ? "pion" : "elec") << " = " << f << " +/- " << f_err << std::endl;
	
	//plotting and printing
	if (do_show){
		TCanvas* can = new TCanvas("sample","sample",700,500);
		can->cd();
		TPad* pad = new TPad("graph","",0,0,1,1);
		pad->SetMargin(0.12,0.05,0.15,0.05);
		pad->Draw();
		pad->cd();
		
		//formatting
		hsam->SetTitle("");
		hsam->GetXaxis()->SetTitle("Energy [GeV]");
		//hsam->SetStats(kTRUE);
		//gStyle->SetOptStat("mr");
		hsam->SetLineWidth(2);
		hsam->SetLineColor(kBlack);
		hsam->GetYaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC()));
		hsam->GetYaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC()));
		hsam->GetXaxis()->SetTitleSize(32/(pad->GetWh()*pad->GetAbsHNDC()));
		hsam->GetXaxis()->SetLabelSize(28/(pad->GetWh()*pad->GetAbsHNDC()));
		hsam->GetYaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC()));
		hsam->GetXaxis()->SetTickLength(12/(pad->GetWh()*pad->GetAbsHNDC()));
		
		hsam->Draw();
		
		std::stringstream Nname;
		Nname << "N = " << N;
		
		//determine placing of pave
		Double_t xmin;
		if (m/((hsam->GetXaxis()->GetXmax() + hsam->GetXaxis()->GetXmin())/2) < 1) xmin = 0.65;
		else xmin = 0.2;
		
		//legend
		TPaveText *pave = new TPaveText(xmin,0.65,xmin+0.2,0.85,"NDC");
		pave->AddText((piname.str()).c_str());
		pave->AddText((Nname.str()).c_str());
		pave->AddText("Peak sampling factor:");
		pave->AddText((s_mean.str()).c_str());
		pave->SetFillColor(0);
		pave->SetBorderSize(0);
		pave->SetTextFont(42);
		pave->SetTextSize(0.05);
		pave->Draw("same");

		if(do_print) {
			std::stringstream oname;
			oname << pdir << "/" << fpre << "_sample_" << energy << "gev_peak.png";
			can->Print((oname.str()).c_str(),"png");
		}
	}
	else _file->Close();

	//store value in sample
	if(set_val){
		if(do_pion) sp->sam_pion = f;
		else sp->sam_elec = f;
	}

	return std::pair<Double_t,Double_t>(f,f_err);
}