Example #1
0
TGraph *MarcosExclusionLine(TH2F *exclusionshape, int scantype) {
//  write_warning(__FUNCTION__,"USING MARIAS ALGORITHM...");
//  return get_exclusion_line(exclusionshape);
  
  TH2F *fakehisto = flipth2f(exclusionshape);
  TGraph *fakegraph = get_mSUGRA_exclusion_line(fakehisto, scantype);
  TGraph *realgraph = new TGraph(fakegraph->GetN());
  double x,y;
  float last_x=0;
  float last_y=0;
  int counter=0;
  for(int i=0;i<fakegraph->GetN();i++) {
	fakegraph->GetPoint(i,x,y);
	if(scantype==PlottingSetup::SMS) {
	  if(y-x<75) {
	    realgraph->SetPoint(counter,last_x,last_y);
	    counter++;
	    continue;
	  }
	}
	realgraph->SetPoint(counter,y,x);
	last_x=y;
	last_y=x;
	counter++;
  }
  realgraph->SetLineColor(TColor::GetColor("#151515")); //nice black
  realgraph->SetLineWidth(2);
  //realgraph->SetLineWidth(4);//paper style
  
  delete fakegraph;

  return realgraph;
}
Example #2
0
void ButkevichDrawer::adjust_graph(TGraph& graph) {
  for (int iPoint=0;iPoint<graph.GetN();iPoint++) {
    double x,y;
    graph.GetPoint(iPoint,x,y);
    graph.SetPoint(iPoint,x,y*1.0e-38);
  }
}
std::vector<double> GetCrossings(TGraph const& g, double cross) {
  std::vector<double> result;
  unsigned n = g.GetN();
  double x1 = 0;
  double y1 = 0;
  double x2 = 0;
  double y2 = 0;
  for (unsigned i = 0; i < (n-1); ++i) {
    g.GetPoint(i, x1, y1);
    g.GetPoint(i+1, x2, y2);
    if ( (y2-cross)*(y1-cross) < 0.0 ) {
      double m = (y2-y1)/(x2-x1);
      double c = (y1 - m * x1);
      double xc = (cross - c) / m;
      result.push_back(xc);
      std::cout << "Crossing at " << xc << std::endl;
    }
  }
  return result;
}
Example #4
0
void KVIDentifier::CopyGraph(const TGraph& graph)
{
   // Copy coordinates of points from the TGraph

   Double_t x, y;
   //change number of points
   Set(graph.GetN());
   for (int i = 0; i < GetN(); i++) {
      graph.GetPoint(i, x, y);
      SetPoint(i, x, y);
   }
}
TGraph* ContourGraph( TH2F* hist,double xmin=16, double xmax=90) {

    //temporary canvas
    TCanvas* MOO = new TCanvas( TString::Format("dummy_canvas_%s", hist->GetName()), "A scan of m_{0} versus m_{12}", 0, 0, 650,640);
    MOO->cd();

    TGraph* gr0 = new TGraph();
    TH2F* h = (TH2F*)hist->Clone();
    TGraph* gr = (TGraph*)gr0->Clone(TString::Format("gr_%s", h->GetName()));

    cout << "==> Will dumb histogram: " << h->GetName() << " into a graph" <<endl;

    h->SetContour( 1 );
    //h->GetXaxis()->SetRangeUser(250,1200);
    h->GetXaxis()->SetRangeUser(xmin, xmax);
    //h->GetYaxis()->SetRangeUser(2,50);

    double pval = CombinationGlob::cl_percent[1];
    std::cout << pval << std::endl; 
    double signif = TMath::NormQuantile(1-pval);
    h->SetContourLevel( 0, signif );
    h->Draw("CONT LIST");
    h->SetDirectory(0);
    gPad->Update();

    TObjArray *contours = (TObjArray*) gROOT->GetListOfSpecials()->FindObject("contours");
    Int_t ncontours     = contours->GetSize();
    cout << "Found " << ncontours << " contours " << endl;

    TList *list = (TList*)contours->At(0);
    contours->Print("v");
    if(!list) return NULL;

    gr = (TGraph*)list->First();
    if(!gr) return NULL;

    gr->SetName(TString::Format("gr_%s", hist->GetName()));
    //gr->SetName(hist->GetName());
    int N = gr->GetN();
    double x0, y0;
    for(int j=0; j<N; j++) {
        gr->GetPoint(j,x0,y0);
        cout << j << " : " << x0 << " : "<<y0 << endl;
    }
    //  //  gr->SetMarkerSize(2.0);    
    //gr->Draw("ALP");

    delete MOO;

    cout << "Generated graph " << gr << " with name " << gr->GetName() << endl;
    return gr;
}
Example #6
0
void drawtext()
{
   Int_t i,n;
   Double_t x,y;
   TLatex *l;

   TGraph *g = (TGraph*)gPad->GetListOfPrimitives()->FindObject("Graph");
   n = g->GetN();
   for (i=1; i<n; i++) {
      g->GetPoint(i,x,y);
      l = new TLatex(x,y+0.2,Form("%4.2f",y));
      l->SetTextSize(0.025);
      l->SetTextFont(42);
      l->SetTextAlign(21);
      l->Paint();
   }
}
vector< pair <double,double> > getMinMaxOfGraphs (vector<GraphInfo> inputGraphs) {

  cout << "-----------------Inside minMax -------------------" << endl;
  pair<double,double> yValMinMax;
  pair<double,double> xValMinMax;
  
  yValMinMax.first = 1000.0; //min
  yValMinMax.second = -1000.0; //max

  xValMinMax.first = 1000.0; //min
  xValMinMax.second = -1000.0; //max
  
  
  for (unsigned iGraph =0; iGraph < inputGraphs.size(); iGraph++){
    TGraph * thisGraph = inputGraphs[iGraph].theGraph;
    
    double iMinY = 1000.0;
    double iMaxY = -1000.0;
    double iMinX = 1000.0;
    double iMaxX = -1000.0;

    
    for (int iPoint =0; iPoint < thisGraph->GetN(); iPoint++){
      double xVal, yVal;
      thisGraph->GetPoint(iPoint, xVal, yVal);
      cout <<"n = " << iPoint << "x= " << xVal << "y = " << yVal << endl;
      if (yVal < iMinY )
        iMinY = yVal;
      if (yVal > iMaxY)
        iMaxY = yVal;

      if (xVal < iMinX )
        iMinX = xVal;
      if (xVal > iMaxX)
        iMaxX = xVal;
      
    }
    
    cout << "New plot minY = " << iMinY << ", maxY = " << iMaxY << endl
         << "         minX = " << iMinX << ", maxX = " << iMaxX << endl ;

    if (iMinY < yValMinMax.first)
      yValMinMax.first = iMinY;
    if (iMaxY > yValMinMax.second)
      yValMinMax.second = iMaxY;

    if (iMinX < xValMinMax.first)
      xValMinMax.first = iMinX;
    if (iMaxX > xValMinMax.second)
      xValMinMax.second = iMaxX;
    
  }

  //------------------------

  cout << "found min = " << yValMinMax.first
       << "   found max = " << yValMinMax.second
       << endl;

  if (yValMinMax.first > 0 )
    yValMinMax.first = 0;

  vector<pair<double,double> >  returnValMinMax;
  returnValMinMax.push_back(xValMinMax);
  returnValMinMax.push_back(yValMinMax);
  
  return returnValMinMax;
                                        
}
Example #8
0
void draw_mSUGRA_exclusion(TH2F *ocrosssection, TH2F *oFilterEfficiency, TH2F *oabsXS, TH2F *limitmap, TH2F *expmap, TH2F *expplusmap, TH2F *expminusmap, TH2F *exp2plusmap, TH2F *exp2minusmap, bool isobserved) {
  TH2F *crosssection = (TH2F*)ocrosssection->Clone("crosssection");
//  TH2F *limitmap = (TH2F*)olimitmap->Clone(((string)olimitmap->GetName()+"clone").c_str());
  TH2F *cleanhisto = (TH2F*)limitmap->Clone("clean");
  for(int ix=1;ix<=cleanhisto->GetNbinsX();ix++) {
    for(int iy=1;iy<=cleanhisto->GetNbinsY();iy++) {
      cleanhisto->SetBinContent(ix,iy,0);
    }
  }
  
  
  TH2F *FilterEfficiency;
  TH2F *absXS;

  
  
  
  write_warning(__FUNCTION__,"You'll want to switch off 'wrongwaytodothis')");
  
  if(wrongwaytodothis) {
    //this part is the one you want to remove.
    TFile *Efficiencies = new TFile("FilterEfficiencyv3.root");
    FilterEfficiency = cast_into_shape((TH2F*) Efficiencies->Get("FilterEfficiency"),limitmap);
    assert(FilterEfficiency);
    assert(crosssection);
    absXS=(TH2F*)crosssection->Clone("absXS");
    crosssection->Multiply(FilterEfficiency);
  } else {
    //this part is the one you want to keep!
    FilterEfficiency=(TH2F*)oFilterEfficiency->Clone("FilterEfficiency");
    absXS=(TH2F*)oabsXS->Clone("absXS");
  }
    
  

  TH2F *limits = (TH2F*)limitmap->Clone("limits");
  set_range(limits,true,false);
  limitmap->Divide(crosssection);
  expminusmap->Divide(crosssection);
  expplusmap->Divide(crosssection);
  exp2minusmap->Divide(crosssection);
  exp2plusmap->Divide(crosssection);
  expmap->Divide(crosssection);
  TGraph *observed = get_mSUGRA_exclusion_line(limitmap, PlottingSetup::mSUGRA);
  observed->SetLineColor(kRed);
  TGraph *expminus = get_mSUGRA_exclusion_line(expminusmap, PlottingSetup::mSUGRA);
  TGraph *expplus  = get_mSUGRA_exclusion_line(expplusmap, PlottingSetup::mSUGRA);
  TGraph *exp2minus;
  if(draw2sigma) exp2minus = get_mSUGRA_exclusion_line(exp2minusmap, PlottingSetup::mSUGRA);
  TGraph *exp2plus;
  if(draw2sigma) exp2plus = get_mSUGRA_exclusion_line(exp2plusmap, PlottingSetup::mSUGRA);

  TGraph *expected = new TGraph(expminus->GetN()+expplus->GetN());
  TGraph *expected2; 
  if(draw2sigma) expected2 = new TGraph(exp2minus->GetN()+exp2plus->GetN());
  for(int i=0;i<=expminus->GetN();i++) {
    Double_t x,y;
    expminus->GetPoint(i,x,y);
    expected->SetPoint(i,x,y);
  }
    
  for(int i=0;i<=exp2minus->GetN();i++) {
    Double_t x,y;
    exp2minus->GetPoint(i,x,y);
    expected2->SetPoint(i,x,y);
  }
  for(int i=exp2plus->GetN()-1;i>=0;i--) {
    Double_t x,y;
    exp2plus->GetPoint(i,x,y);
    expected2->SetPoint(exp2minus->GetN()+(exp2plus->GetN()-i),x,y);
  }
  for(int i=expplus->GetN()-1;i>=0;i--) {
    Double_t x,y;
    expplus->GetPoint(i,x,y);
    expected->SetPoint(expminus->GetN()+(expplus->GetN()-i),x,y);
  }
  expected->SetFillColor(TColor::GetColor("#9FF781"));
  if(draw2sigma) expected2->SetFillColor(TColor::GetColor("#F3F781"));
  
  smooth_line(observed);
  smooth_line(expected);
  if(draw2sigma) smooth_line(expected2);
  
  TCanvas *te = new TCanvas("te","te");
  te->SetRightMargin(standardmargin);
//  decorate_mSUGRA(cleanhisto,te,expected,expected2,observed);
  TH2F *noh = new TH2F("noh","noh",1,1,2,1,1,2);
  SugarCoatThis(te,10,noh,observed);
//  expected->Draw("c");
//  observed->Draw("c");
  stringstream saveas;
  if((int)((string)limitmap->GetName()).find("limitmap")>0) {
    saveas << "Limits/";
    if(!isobserved) saveas << "expected/expected_";
    saveas << "final_exclusion_for_JZB_geq_" << ((string)limitmap->GetName()).substr(((string)limitmap->GetName()).find("limitmap")+8,10);
  } else {
    saveas << "Limits/";
    if(!isobserved) saveas << "expected/expected";
    saveas << "final_exclusion_for_bestlimits";
  }
  CompleteSave(te,saveas.str());
  delete te;
  
  TCanvas *overview = new TCanvas("overview","overview",1500,1000);
  
  set_range(crosssection,true,false);
  set_range(limits,true,false);
  set_range(limitmap,true,false);
  
  overview->Divide(3,2);
  overview->cd(1);
  overview->cd(1)->SetLogz(1);
  absXS->GetZaxis()->SetRangeUser(0.0001,100);
  absXS->Draw("COLZ");
  TText *title0 = write_title("Cross Section");
  title0->Draw("same");
  overview->cd(2);
  FilterEfficiency->GetZaxis()->SetRangeUser(0.01,0.7);
  FilterEfficiency->Draw("COLZ");
  TText *title0aa = write_title("Filter #epsilon");
  title0aa->Draw("same");
  overview->cd(3);
  overview->cd(3)->SetLogz(1);
  crosssection->GetZaxis()->SetRangeUser(0.0001,100);
  crosssection->Draw("COLZ");
  TText *title0a = write_title("Filter #epsilon x Cross Section");
  title0a->Draw("same");
  
  overview->cd(4);
  overview->cd(4)->SetLogz(1);
  limits->GetZaxis()->SetRangeUser(0.01,100);
  limits->Draw("COLZ");
  TText *title1 = write_title("Cross Section Upper Limit");
  title1->Draw("same");
  overview->cd(5);
  limitmap->Draw("COLZ");
  TText *title2 = write_title("UL/XS");
  title2->Draw("same");
  observed->Draw("c");
  overview->cd(6);
  overview->cd(6)->SetRightMargin(standardmargin);
//  decorate_mSUGRA(cleanhisto,overview->cd(4),expected,expected2,observed);
  SugarCoatThis(overview->cd(6),10,noh,observed);
//  observed->Draw("c");
  stringstream saveas2;
  if((int)((string)limitmap->GetName()).find("limitmap")>0) {
    saveas2 << "Limits/";
    if(!isobserved) saveas << "expected/expected_";
    saveas2 << "exclusion_overview_for_JZB_geq_" << ((string)limitmap->GetName()).substr(((string)limitmap->GetName()).find("limitmap")+8,10);
  } else {
    saveas2 << "Limits/";
    if(!isobserved) saveas << "expected/expected_";
    saveas2 << "exclusion_overview_for_bestlimits";
  }
  CompleteSave(overview,saveas2.str());
  delete overview;
  delete noh;
  delete crosssection;
  delete absXS;
  delete FilterEfficiency;
  
}
Example #9
0
void slopetest(){

   string dist = "maos210";
   double nevts = 2*50000.0;
   string dim = "mt";

   double p1=0, p2=0, p3=0;
   double dx = 0;
   double eps = 0.2;
   if( dim == "mt" ){
      p1 = 172.0; p2 = 172.5, p3 = 173.0;
      //p1 = 172.5; p2 = 173, p3 = 173.5;
      //p1 = 166.0; p2 = 166.5, p3 = 167.0;
      //p1 = 178.0; p2 = 178.5, p3 = 179.0;
   }
   if( dim == "jes" ){
      p1 = 0.999; p2 = 1.000, p3 = 1.001;
   }
   if( dist == "mbl" ){
      dx = 2.8;
   }
   if( dist == "mt2_221" ){
      dx = 1.9;
   }

   TFile *f = new TFile("../results/plotsTemplates.root");
   TDirectory *d = (TDirectory*)f->Get((dim+"shape_"+dist+"_gp").c_str());

   /*
   TCanvas *ctemp = (TCanvas*)f->Get(("c_"+dist+"_gp_signal_JSF1000").c_str());
   TH1 *h = (TH1*)(ctemp->GetListOfPrimitives()->At(1));
   dx = h->GetBinWidth(1);

   delete ctemp;
   */
   dx = 10;

   TGraph *gslope = new TGraph();
   TGraph *gint = new TGraph();

   double sig = 0;
   double d2sig = 0;

   TIter nextkey(d->GetListOfKeys());
   TKey *key;
   while( (key = (TKey*)nextkey()) ){

      string name = key->GetName();
      string classname = key->GetClassName();

      TCanvas *c = (TCanvas*)d->Get(name.c_str());
      TGraph *g = (TGraph*)(c->GetListOfPrimitives()->At(1));

      double y1=0, y2=0;
      double ycent = 0;
      for(int i=0; i < g->GetN(); i++){
         double x=0, y=0;
         g->GetPoint(i, x, y);
         if( x == p1 ) y1 = y;
         if( x == p2 ) ycent = y;
         if( x == p3 ) y2 = y;
      }
      double slope = y2-y1;

      string sbin = name;
      string ntemp = "c"+dist+"_gp";
      sbin.erase(sbin.begin(), sbin.begin()+ntemp.length());
      if( dist == "mt2_221" ) sbin.erase(sbin.end(), sbin.end()+1);
      double dbin = atof(sbin.c_str());

      double integrand = slope*slope/ycent;

      gint->SetPoint(gint->GetN(), dbin, integrand);
      gslope->SetPoint(gslope->GetN(), dbin, slope);

      sig += slope*slope*eps*eps*-0.5*dx/ycent;
      d2sig += integrand*dx;

   }

   cout << "Projected S(" << eps << ") = " << sig-2.0*nevts << endl;
   cout << "Projected sigma = " << sqrt(1.0/(d2sig*nevts)) << endl;

   TCanvas *c1 = new TCanvas();
   gslope->SetLineWidth(2);
   gslope->GetXaxis()->SetTitle("(GeV)");
   gslope->GetXaxis()->SetTitleSize(0.05);
   gslope->GetXaxis()->SetTitleOffset(0.8);
   gslope->Draw("AC");

   TCanvas *c2 = new TCanvas();
   gint->SetLineWidth(2);
   gint->GetXaxis()->SetTitle("(GeV)");
   gint->GetXaxis()->SetTitleSize(0.05);
   gint->GetXaxis()->SetTitleOffset(0.8);
   gint->Draw("AC");

   return;
}
Example #10
0
void alicePlots(){
    
    TFile* alice = new TFile("~/Downloads/HEPData-ins1288320-v1-root.root");
    alice->cd("Table 16");
    TGraph* aliceData = Graph1D_y1;
    TH1F* hist = Hist1D_y1;
    TH1F* stat = Hist1D_y1_e1;
    TH1F* syst = Hist1D_y1_e2;
    TGraphAsymmErrors* graph2 = (TGraphAsymmErrors*)aliceData->Clone("graph2");

    Int_t numPts = aliceData->GetN();
    Double_t x, y;
    for(int i = 0; i<numPts; i++){
        aliceData->GetPoint(i, x, y);
        aliceData->SetPoint(i, x, (y - 0.89581));
        graph2->SetPoint(i, x, (y- 0.89581));
        hist->SetBinContent(i+1, hist->GetBinContent(i+1) - 0.89581);
        hist->SetBinError(i+1, stat->GetBinContent(i+1));
        graph2->SetPointEXhigh(i, 0.1);
        graph2->SetPointEXlow(i, 0.1);
    }

    graph2->SetLineColor(kBlue-10);
    graph2->SetLineWidth(2);
    graph2->SetMarkerColor(kBlue-10);
    graph2->SetFillColor(kBlue-10);
    hist->SetLineColor(kBlue-2);
    hist->SetLineWidth(2);

    aliceData->SetTitle("");
    aliceData->GetYaxis()->SetTitle("Mass - Vacuum Mass (GeV/c^{2})");
    aliceData->GetYaxis()->SetTitleSize(0.06);
    aliceData->GetYaxis()->SetLabelSize(0.04);
    aliceData->GetYaxis()->SetTitleOffset(1.65);
    aliceData->GetYaxis()->SetTitleFont(42);
    aliceData->GetYaxis()->SetLabelFont(42);
    aliceData->GetXaxis()->SetTitle("p_{T} (GeV/c)");
    aliceData->GetXaxis()->SetTitleSize(0.06);
    aliceData->GetXaxis()->SetLabelSize(0.05);
    aliceData->GetXaxis()->SetTitleFont(42);
    aliceData->GetXaxis()->SetLabelFont(42);
    aliceData->SetMarkerStyle(29);
    aliceData->SetMarkerSize(2.5);
    aliceData->SetMarkerColor(kBlue-2);
    aliceData->SetLineColor(kBlue-2);

    aliceData->GetYaxis()->SetRangeUser(-0.02, 0.015);
    aliceData->GetXaxis()->SetRangeUser(0, 5);

    TFile* phsd = new TFile("~/utaustin/resonancefits/finalplotting/20170721_KKbarAdded2_fixedwidth42_recon_pf100_scaled_error05.root");
    TH1D* mass = phsd->Get("kstar0mass");
    mass->SetName("mass");
    mass->SetMarkerStyle(26);
    mass->SetMarkerSize(2.5);
    mass->SetMarkerColor(2);
    mass->SetLineColor(2);

    TF1* line = new TF1("line", "[0]", 0.0, 5.0);
    line->SetParameter(0, 0.0);
    line->SetLineColor(1);
    line->SetLineStyle(7);
    line->SetLineWidth(3);

    for(int j = 0; j<mass->GetNbinsX(); j++){
        mass->SetBinContent(j+1, (mass->GetBinContent(j+1) - 0.892));
    }


    TFile* phsd2 = new TFile("~/utaustin/resonancefits/finalplotting/20170616_KKbarAdded2_fixedwidth_recon_pf100_scaled_error05.root");
    TH1D* mass2 = phsd2->Get("kstar0mass");
    mass2->SetName("mass2");
    mass2->SetMarkerStyle(22);
    mass2->SetMarkerSize(2.5);
    mass2->SetMarkerColor(2);
    mass2->SetLineColor(2);
    for(int j = 0; j<mass2->GetNbinsX(); j++){
        mass2->SetBinContent(j+1, (mass2->GetBinContent(j+1) - 0.892));
    }



    TExec *exec1 = new TExec("exec1", "gStyle->SetErrorX(0.1)");
    TExec *exec2 = new TExec("exec2", "gStyle->SetErrorX(0.5)");
    
    TCanvas *c = new TCanvas ("c", "c", 50, 50, 650, 600);
    c->cd()->SetMargin(0.1997, 0.0369, 0.1396, 0.0681);
    aliceData->Draw("APX");
    //exec1->Draw();
    graph2->Draw("SAME P2");
    //exec2->Draw();
    hist->Draw("SAME E1");
    line->Draw("SAME");
    mass2->Draw("SAME P E1");
    mass->Draw("SAME P E1");
    aliceData->Draw("SAME PX");
    

    TLegend* legend = new TLegend(0.5836, 0.1815, 0.9489, 0.3438);
    legend->SetMargin(0.2);
    legend->SetTextSizePixels(20);
    legend->AddEntry(aliceData, "ALICE data, 0-20%", "p");
    legend->AddEntry(mass2, "Fit IV to PHSD: w in-med", "p");
    legend->AddEntry(mass, "Fit IV to PHSD: w/o in-med", "p");
    legend->Draw("SAME"); 
  
    TPaveText* text = new TPaveText(0.2554, 0.7243, 0.6006, 0.9162, "NDC");
    text->AddText("(K*^{0} + #bar{K}*^{0})");
    text->AddText("Pb-Pb #sqrt{s_{NN}} = 2.76 TeV");
    text->GetLine(0)->SetTextSizePixels(36);
    text->GetLine(1)->SetTextSizePixels(24);
    text->SetTextFont(42);
    text->SetBorderSize(0);
    text->SetFillStyle(0);
    text->Draw();
}
void makePlots( const char * modelA, 
                const char * modelB,
                const char * modelC, 
                const char * src, 
                const char * config,
                const char * infileA,  
                const char * infileB,  
                const char * infileC,
                const char * infileD )
{
  
  bool use_color = true;
  
  int color[3] = {1, 4, 2}; //black, blue, red
 
  int lineStyle[3] = { 1 , 2 , 3};
      
  int lineWidth = 2;
  
  //Output path
  TString path("./paper01-plots/ratio/");

  TFile * f1 = new TFile(infileA);
  TFile * f2 = new TFile(infileB);
  TFile * f3 = new TFile(infileC);
  TFile * f4 = new TFile(infileD); // This is the Vacuum model inside Earth

  TList * v_Data = new TList();
  TObjString *data;

  //Vaccum
  data = new TObjString( TString( "ZeroPt" )  + TString("_") + TString( src ) + TString("_Pee/data") );
  v_Data->Add( data );
  //A
  data = new TObjString( TString( modelA )    + TString("_") + TString( src ) + TString("_Pee/data") );
  v_Data->Add( data );
  //B
  data = new TObjString( TString( modelB )    + TString("_") + TString( src ) + TString("_Pee/data") );
  v_Data->Add( data );
  //anti A
  data = new TObjString( TString( modelC )    + TString("_") + TString( src ) + TString("_Pee/data") );
  v_Data->Add( data );
  
  TList * v_Labels = new TList();
  TObjString *label;
  label = new TObjString( "#phi ( E_{#nu} )" );
  v_Labels->Add( label ); 
  label = new TObjString( "#phi ( E_{#nu} )" );
  v_Labels->Add( label ); 
  label = new TObjString( "#phi ( E_{#nu} ) " );
  v_Labels->Add( label ); 
  label = new TObjString( "#phi ( E_{#nu} ) " );
  v_Labels->Add( label ); 

  TList * v_Title = new TList();
  label = new TObjString( "(0) Vacuum" );
  v_Title->Add( label ); 
  label = new TObjString( "(a) Model A" );
  v_Title->Add( label ); 
  label = new TObjString( "(b) Model B" );
  v_Title->Add( label ); 
  label = new TObjString( "(c) Model C" );
  v_Title->Add( label );
  
  TList * PeeTree = new TList();
  TList * PhiGraphs = new TList();
  TList * RatioGraphs = new TList();
  TList * VacuumGraphs = new TList();

  TLegend * leg = new TLegend(0.14,0.69,0.24,0.85);

  TString treeName = ((TObjString*)v_Data->At(0))->GetString();
  f4->cd();
  PeeTree->Add( (TTree*)gDirectory->Get( treeName.Data() ) );
  std::cout << treeName << " " << (TTree*)gDirectory->Get( treeName.Data() ) << std::endl;
  
  treeName = ((TObjString*)v_Data->At(1))->GetString();
  f1->cd(); //ModelA 
  PeeTree->Add( (TTree*)gDirectory->Get( treeName.Data() ) );
  std::cout << treeName << " " << (TTree*)gDirectory->Get( treeName.Data() ) << std::endl;
  
  treeName = ((TObjString*)v_Data->At(2))->GetString();
  f2->cd(); //ModelB
  PeeTree->Add( (TTree*)gDirectory->Get( treeName.Data() ) );
  std::cout << treeName << " " << (TTree*)gDirectory->Get( treeName.Data() ) << std::endl;
  
  treeName = ((TObjString*)v_Data->At(3))->GetString();
  f3->cd(); //ModelC 
  PeeTree->Add( (TTree*)gDirectory->Get( treeName.Data() ) );
  std::cout << treeName << " " << (TTree*)gDirectory->Get( treeName.Data() ) << std::endl;
  
  for( int k = 0; k < 4; ++k ) 
  {
    //Branches
    double xx = 0.0;
    double phi_e = 0.0;
    double phi_m = 0.0;
    double phi_t = 0.0;
    
    TTree * currentTree = (TTree*)PeeTree->At(k);
    
    currentTree->SetBranchAddress("Ex",&xx);
    currentTree->SetBranchAddress("Phi_e",&phi_e);
    currentTree->SetBranchAddress("Phi_m",&phi_m);
    currentTree->SetBranchAddress("Phi_t",&phi_t);
    
    Long64_t nentries = currentTree->GetEntries();
    
    TGraph * g1 = new TGraph();
    TGraph * g2 = new TGraph();
    TGraph * g3 = new TGraph();
    
    int np = 0;
    
    for (Long64_t i=0;i<nentries;i++) {
      currentTree->GetEntry(i);
      
      g1->SetPoint( np, xx, phi_e);
      g2->SetPoint( np, xx, phi_m);
      g3->SetPoint( np, xx, phi_t);
      np++;
      
    }
    
    PhiGraphs->Add( g1 );
    PhiGraphs->Add( g2 );
    PhiGraphs->Add( g3 );
  
    std::cout << " * " << g1 << " " << g2 << " " << g3 << std::endl;
    
  }
  
  int idx = 1;
  int idxc = 1;
  int nGraphs = PhiGraphs->GetSize();
  
  //..................................................................................................

  TCanvas * c1 = new TCanvas(modelA, "Oscillation probabilities", 184, 60, 861, 670);
  c1->Divide(1,4); 
  c1->Draw();

  for( int k=0; k < nGraphs; ++k) 
  {
    
    if ( idx >= 4 ) idx = 1;
    
    TGraph * g1 = (TGraph*)PhiGraphs->At(k);
    
    g1->SetLineWidth(2); 
    
    if ( idx == 1 ) 
    {
      
      std::cout << idxc << " " << idx << std::endl;
      
      c1->cd( idxc );
            
      gPad->SetGridx();
      gPad->SetGridy();
      gPad->SetLogx();
      //gPad->SetLogy();

      

      g1->SetMarkerStyle(1);
      g1->SetFillColor(10);
      g1->SetMaximum(1.04);
      g1->SetMinimum(-0.05);
      
      g1->GetYaxis()->SetNdivisions(504);
      TString yaxis = ((TObjString*)v_Labels->At( idxc-1))->GetString();
      g1->GetYaxis()->SetTitle( yaxis.Data() );
      g1->GetXaxis()->SetTitle("E_{#nu} (eV)");
      g1->GetYaxis()->CenterTitle(true); 
      g1->GetXaxis()->CenterTitle(true); 
      g1->GetXaxis()->SetLabelOffset(0.007);
      g1->GetXaxis()->SetLabelSize(0.10);
      g1->GetXaxis()->SetTitleSize(0.11);
      g1->GetXaxis()->SetTitleOffset(0.5);
      g1->GetXaxis()->SetLabelFont(22);
      g1->GetXaxis()->SetTitleFont(22);
      g1->GetYaxis()->SetLabelOffset(0.007);
      g1->GetYaxis()->SetLabelSize(0.10);
      g1->GetYaxis()->SetTitleSize(0.16);
      g1->GetYaxis()->SetTitleOffset(0.25);
      g1->GetYaxis()->SetTitleFont(22);
      g1->GetYaxis()->SetLabelFont(22);

      g1->SetLineStyle( lineStyle[idx-1] );
      
      g1->SetLineColor( 1 );

      if( use_color ) g1->SetLineColor( color[idx-1] );
      
      g1->Draw("AL");

      TString title = ((TObjString*)v_Title->At(idxc-1))->GetString();
      topTitle(title.Data());
      
      //
      if ( idxc == 1 ) 
      {
        
        char HistoName[20];
        sprintf(HistoName,"H1_%d", k);
        TGraph * h1 = g1->Clone(HistoName);
        VacuumGraphs->Add( h1 );
        std::cout << " graph " << k << " == in vacuum" << h1 << " " << std::string(HistoName) << std::endl;
        
      }
        
    }
              
    else if ( idx == 2 ) {

      std::cout << " - " << idxc << " " << idx << std::endl;
      
      g1->SetLineColor( 1 );
      
      if( use_color ) g1->SetLineColor( color[idx-1] );
      
      g1->SetLineStyle( lineStyle[idx-1] );
      
      g1->Draw("L");
      
      if ( idxc == 1 ) 
      {
        
        char HistoName[20];
        sprintf(HistoName,"H1_%d", k);
        TGraph * h1 = g1->Clone(HistoName);
        VacuumGraphs->Add( h1 );
        std::cout << " graph " << k << " == in vacuum" << h1 << " " << std::string(HistoName) << std::endl;

      }
      
    } else if ( idx == 3 ) {
      
      std::cout << " -- "<< idxc << " " << idx << std::endl;
      
      g1->SetLineColor( 1 );
      
      if( use_color ) g1->SetLineColor( color[idx-1]);
      
      g1->SetLineStyle( lineStyle[idx-1] );
      
      g1->Draw("L");
      
      if ( idxc == 1 ) 
      {
        
        char HistoName[20];
        sprintf(HistoName,"H1_%d", k);
        TGraph * h1 = g1->Clone(HistoName);
        VacuumGraphs->Add( h1 );
        std::cout << " graph " << k << " == in vacuum" << h1 << " " << std::string(HistoName) << std::endl;

      }
      
      idxc += 1;
      
    } else { }
   
    TLine *line = new TLine(7.9e+10,0.333,2.25e+14,0.333);
    line->SetLineColor(3);
    line->SetLineStyle(2);
    line->SetLineWidth(2);
    line->Draw("same");

 
    idx += 1;
        
  }
  
  c1->cd();

  //..................................................................................................

  idx = 1;

  double xp1 = 0.0;
  double xp2 = 0.0;
    
  for( int k = 3; k < nGraphs; ++k) 
  {
    
    if ( idx >= 4 ) idx = 1;
    
    TGraph * g1 = (TGraph*)PhiGraphs->At(k);
    
    int maxpts = g1->GetN();
    
    xx = 0.0;
    double y1    = 0.0;
    double y2    = 0.0;
    double ratio = 1.0;
    
    TGraph * r1 = new TGraph();
    int np = 0;
    
    if( idx == 1 ) 
    {
      
      TGraph * denom = (TGraph*)VacuumGraphs->At(0);
      np = 0;
      for( int j = 0; j < maxpts; ++j) 
      {
        
        g1->GetPoint(j, xp1, y1);
        denom->GetPoint(j, xp2, y2);
        if ( y2 <= 1.0e-3 ) continue;
        ratio = y1/y2;

        if (ratio > 5 ) std::cout << " nu_e> x1= " << xp1 << " x2= " << xp2 << " num= " 
                                  << y1 << " den= " << y2 << " num/den= " << ratio << std::endl;

        r1->SetPoint( np, xp1, ratio );
        ++np;
      }
      
      RatioGraphs->Add(r1);
      std::cout << " ratio added " << std::endl;
      
    } else if ( idx == 2 ) 
    {

      TGraph * denom = (TGraph*)VacuumGraphs->At(1);
      np = 0;
      for( int j = 0; j < maxpts; ++j) 
      {

        g1->GetPoint(j, xp1, y1);
        denom->GetPoint(j, xp2, y2);
        if ( y2 <= 1.0e-3 ) continue;
        ratio = y1/y2;
        if (ratio > 5 ) std::cout << " nu_e> x1= " << xp1 << " x2= " << xp2 << " num= " 
                                  << y1 << " den= " << y2 << " num/den= " << ratio << std::endl;
        r1->SetPoint( np, xp1, ratio );
        ++np;
      }
      
      RatioGraphs->Add(r1);
      std::cout << " ratio added " << std::endl;

    } else if ( idx == 3 ) 
    {

      TGraph * denom = (TGraph*)VacuumGraphs->At(2);
      np = 0;
      for( int j = 0; j < maxpts; ++j) 
      {
        
        g1->GetPoint(j, xp1, y1);
        denom->GetPoint(j, xp2, y2);
        if ( y2 <= 1.0e-3 ) continue;
        ratio = y1/y2;
        if (ratio > 5 ) std::cout << " nu_e> x1= " << xp1 << " x2= " << xp2 << " num= " 
                                  << y1 << " den= " << y2 << " num/den= " << ratio << std::endl;
        r1->SetPoint( np, xp1, ratio );
        ++np;
      }
      
      RatioGraphs->Add(r1);
      std::cout << " ratio added " << std::endl;

    } else {}
                
    idx += 1;
    
  }

  c1->cd(1);
  TGraph * g1 = (TGraph*)PhiGraphs->At(0);
  g1->Draw("L");
  c1->cd(2);
  g1 = (TGraph*)PhiGraphs->At(3);
  g1->Draw("L");
  c1->cd(3);
  g1 = (TGraph*)PhiGraphs->At(6);
  g1->Draw("L");
  c1->cd(4);
  g1 = (TGraph*)PhiGraphs->At(9);
  g1->Draw("L");
     
  c1->cd();


  std::stringstream saveAs;
    
  saveAs.str("");
  saveAs << path << modelA << "/pdf/" << "nueosc_flux_" << config << "_Models_ABC_Vac" << ".pdf";
  c1->SaveAs( saveAs.str().c_str() );
  
  saveAs.str("");
  saveAs << path << modelA << "/png/" << "nueosc_flux_" << config << "_Models_ABC_Vac" << ".png";
  c1->SaveAs( saveAs.str().c_str() );

  saveAs.str("");
  saveAs << path << modelA << "/eps/" << "nueosc_flux_" << config << "_Models_ABC_Vac" << ".eps";
  c1->SaveAs( saveAs.str().c_str() );
  

  //..................................................................................................

  Float_t small = 1e-5; //Referee request

  TCanvas * c2 = new TCanvas("Ratios", "Oscillation probabilities - Ratios", 184, 60, 861, 670);
  c2->Divide(1,3,small,small);
  c2->Draw();
  c2->cd();
  
  //
  idx = 1;
  idxc = 1;
  nGraphs = RatioGraphs->GetSize();

  for( int k=0; k < nGraphs; ++k) 
  {
    
    if ( idx >= 4 ) idx = 1;
     
    TGraph * g1 = (TGraph*)RatioGraphs->At(k);
    
    g1->SetLineWidth(lineWidth); 
    
    std::cout << " g1 " << g1 << std::endl;
      
    if ( idx == 1 ) 
    {
      
      std::cout << idxc << " " << idx << std::endl;
      
      c2->cd( idxc );
      
      //Referee request
    
      if ( idxc == 1 )
        gPad->SetBottomMargin(small);
      else if ( idxc == 3)
        gPad->SetTopMargin(small);
      else { }
      
      if ( idxc == 2 ) 
      {
        gPad->SetBottomMargin(small);
        gPad->SetTopMargin(small);
      }
      
      // ......................

      gPad->SetGridx();
      gPad->SetGridy();
      gPad->SetLogx();
      //gPad->SetLogy();
      
        
      g1->SetMarkerStyle(1);
      g1->SetFillColor(10);
      
      g1->SetMaximum(21.00);
      g1->SetMinimum(-1.05);
      
      g1->GetYaxis()->SetNdivisions(504);
      TString yaxis = ((TObjString*)v_Labels->At( idxc-1))->GetString();
      g1->GetYaxis()->SetTitle( "#phi/#phi_{vac}" );

      g1->GetXaxis()->SetTitle("E_{#nu} (eV)          ");
      g1->GetXaxis()->CenterTitle(true); 
      g1->GetXaxis()->SetLabelOffset(0.007);
      g1->GetXaxis()->SetLabelSize(0.10);
      g1->GetXaxis()->SetTitleSize(0.11);
      g1->GetXaxis()->SetTitleOffset(0.5);
      g1->GetXaxis()->SetLabelFont(22);
      g1->GetXaxis()->SetTitleFont(22);
      g1->GetXaxis()->SetTickLength(0.05);

      g1->GetYaxis()->CenterTitle(true); 
      g1->GetYaxis()->SetLabelOffset(0.007);
      g1->GetYaxis()->SetLabelSize(0.10);
      g1->GetYaxis()->SetTitleSize(0.16);
      g1->GetYaxis()->SetTitleOffset(0.25);
      g1->GetYaxis()->SetTitleFont(22);
      g1->GetYaxis()->SetLabelFont(22);
      g1->GetYaxis()->SetTickLength(0.05);

      g1->SetLineStyle( lineStyle[idx-1] );
      
      g1->SetLineColor( 1 );

      if( use_color ) g1->SetLineColor( color[idx-1] );
      
      
      g1->Draw("AL");

      TString title = ((TObjString*)v_Title->At(idxc))->GetString();
      topTitle(title.Data());

    } 
    
    else if ( idx == 2 ) {

      std::cout << " - " << idxc << " " << idx << std::endl;

      g1->SetLineColor( 1 );

      if( use_color ) g1->SetLineColor( color[idx-1] );
      
      g1->SetLineStyle( lineStyle[idx-1] );

      g1->Draw("L");
      
    }
 
    else if ( idx == 3 ) {
      
      std::cout << " -- "<< idxc << " " << idx << std::endl;

      g1->SetLineColor( 1 );
      
      if( use_color ) g1->SetLineColor( color[idx-1]);
      
      g1->SetLineStyle( lineStyle[idx-1] );

      g1->Draw("L");
      
      idxc += 1;
      
    } else { }
    
    idx += 1;
    
  }

  
  c2->cd(1);
  TGraph * g1 = (TGraph*)RatioGraphs->At(0);
  g1->Draw("L");
  c2->cd(2);
  g1 = (TGraph*)RatioGraphs->At(3);
  g1->Draw("L");
  c2->cd(3);
  g1 = (TGraph*)RatioGraphs->At(6);
  g1->Draw("L");
   
  c2->cd();
  
  //

  saveAs.str("");
  saveAs << path << modelA << "/pdf/" << "nueosc_flux_" << config << "_4x_Ratios_noLog" << ".pdf";
  c2->SaveAs( saveAs.str().c_str() );
  
  saveAs.str("");
  saveAs << path << modelA << "/png/" << "nueosc_flux_" << config << "_4x_Ratios_noLog" << ".png";
  c2->SaveAs( saveAs.str().c_str() );

  saveAs.str("");
  saveAs << path << modelA << "/eps/" << "nueosc_flux_" << config << "_4x_Ratios_noLog" << ".eps";
  c2->SaveAs( saveAs.str().c_str() );
  
}
Example #12
0
TGraph* getContour(TH2D* h, TString name) {

  TGraph* graph = new TGraph(100);
  graph->SetName(name);
  int ip = 0;
  int nx = h->GetXaxis()->GetNbins();
  int ny = h->GetYaxis()->GetNbins();

  // for y>x
  int ix = -1;
  for(int j=ny;true; j--) {
    int k = -1;
    for(int i=2; i<nx-1; i++) {
      if(h->GetBinContent(i,j) < 0) {
	std::cout << "i,j,z : " << i << ", " << j << ", " << h->GetBinContent(i,j) << std::endl;
        k = i;
        break;
      }
    }// for i
    if(k<0) continue;
    double y = h->GetYaxis()->GetBinCenter(j);
    double x1 = h->GetXaxis()->GetBinCenter(k-1);
    double x2 = h->GetXaxis()->GetBinCenter(k);
    double z1 = h->GetBinContent(k-1,j);
    double z2 = h->GetBinContent(k,j);
    double x = x1 + (x2-x1)*fabs(z1)/fabs(z2-z1);
    std::cout << "y, x1, x2, z1, z2, x : " << y << ", " << x1 << ", " << x2 << ", " << x << ", " << z1 << ", " << z2 << std::endl;
    graph->SetPoint(ip++,x,y);

    if(h->GetYaxis()->GetBinCenter(j) < h->GetXaxis()->GetBinCenter(k)) {
      ix = k;
      break;
    }
  }// for j

  if(ix < 0) std::cout << "Something wrong...." << std::endl;

  // for y<x
  for(int i=ix; i<=nx; i++) {
    int k = -1;
    for(int j=2; j<ny-1; j++) {
      if(h->GetBinContent(i,j) < 0) {
        k = j;
        break;
      }
    }// for j
    if(k<0) continue;
    double x = h->GetXaxis()->GetBinCenter(i);
    double y1 = h->GetYaxis()->GetBinCenter(k-1);
    double y2 = h->GetYaxis()->GetBinCenter(k);
    double z1 = h->GetBinContent(i,k-1);
    double z2 = h->GetBinContent(i,k);
    double y = y1 + (y2-y1)*fabs(z1)/fabs(z2-z1);
    std::cout << "x, y1, y2, z1, z2, y : " << x << ", " << y1 << ", " << y2 << ", " << y << ", " << z1 << ", " << z2 << std::endl;
    graph->SetPoint(ip++,x,y);
  }// for i

  ip = graph->GetN()-1;
  while(1) {
    double x, y;
    graph->GetPoint(ip,x,y);
    if(x>1) break;
    else graph->RemovePoint(ip);
    ip--;
  }

  return graph;
}
int main(){
  
  system("mkdir -p plots");
  RooMsgService::instance().setGlobalKillBelow(RooFit::ERROR);
  TFile *bkgFile = TFile::Open("comb_svn/hgg.inputbkgdata_8TeV_MVA.root");
  TFile *sigFile = TFile::Open("comb_svn/hgg.inputsig_8TeV_nosplitVH_MVA.root");
  RooWorkspace *bkgWS = (RooWorkspace*)bkgFile->Get("cms_hgg_workspace");
  RooWorkspace *sigWS = (RooWorkspace*)sigFile->Get("wsig_8TeV");

  RooRealVar *mass = (RooRealVar*)bkgWS->var("CMS_hgg_mass");
  RooRealVar *mu = new RooRealVar("mu","mu",-5.,5.);

  mass->setBins(320);
  cout << mass->getBins() << endl;
  RooDataSet *dataAll;
  
  int firstCat=1;
  int lastCat=1;
  float mu_low=-1.;
  float mu_high=3.;
  float mu_step=0.01;

  vector<pair<double,TGraph*> > minNlltrack;

  for (int cat=firstCat; cat<=lastCat; cat++){
    RooDataSet *data = (RooDataSet*)bkgWS->data(Form("data_mass_cat%d",cat));
    if (cat==firstCat) dataAll = (RooDataSet*)data->Clone("data_mass_all");
    else dataAll->append(*data);
    RooDataHist *dataBinned = new RooDataHist(Form("roohist_data_mass_cat%d",cat),Form("roohist_data_mass_cat%d",cat),RooArgSet(*mass),*data);
    RooDataSet *sigMC = (RooDataSet*)sigWS->data(Form("sig_mass_m125_cat%d",cat));

    if (!dataBinned || !sigMC){
      cerr << "ERROR -- one of data or signal is NULL" << endl;
      exit(1);
    }
    
    // Construct PDFs for this category using PdfModelBuilder
    PdfModelBuilder modelBuilder;
    modelBuilder.setObsVar(mass);
    modelBuilder.setSignalModifier(mu);
    // For Standard Analysis
    //if (cat>=0 && cat<=3) modelBuilder.addBkgPdf("Bernstein",5,Form("pol5_cat%d",cat));
    //if (cat>=4 && cat<=5) modelBuilder.addBkgPdf("Bernstein",4,Form("pol4_cat%d",cat));
    //if (cat>=6 && cat<=8) modelBuilder.addBkgPdf("Bernstein",3,Form("pol3_cat%d",cat));
    // To Profile Multiple PDFs
    if (cat==0 || cat==1 || cat==2 || cat==3){
      modelBuilder.addBkgPdf("Bernstein",4,Form("pol4_cat%d",cat));
      modelBuilder.addBkgPdf("Bernstein",5,Form("pol5_cat%d",cat));
      modelBuilder.addBkgPdf("Bernstein",6,Form("pol6_cat%d",cat));
      /*
      modelBuilder.addBkgPdf("PowerLaw",1,Form("pow1_cat%d",cat));
      modelBuilder.addBkgPdf("PowerLaw",3,Form("pow3_cat%d",cat));
      modelBuilder.addBkgPdf("PowerLaw",5,Form("pow5_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",1,Form("exp1_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",3,Form("exp3_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",5,Form("exp5_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",1,Form("lau1_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",3,Form("lau3_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",5,Form("lau5_cat%d",cat));
      */
    }
    if (cat==4 || cat==5 || cat==6 || cat==7 || cat==8) {
      modelBuilder.addBkgPdf("Bernstein",3,Form("pol3_cat%d",cat));
      modelBuilder.addBkgPdf("Bernstein",4,Form("pol4_cat%d",cat));
      /*
      modelBuilder.addBkgPdf("PowerLaw",1,Form("pow1_cat%d",cat));
      modelBuilder.addBkgPdf("PowerLaw",3,Form("pow3_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",1,Form("exp1_cat%d",cat));
      modelBuilder.addBkgPdf("Exponential",3,Form("exp3_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",1,Form("lau1_cat%d",cat));
      modelBuilder.addBkgPdf("Laurent",3,Form("lau3_cat%d",cat));
      */
    }
    map<string,RooAbsPdf*> bkgPdfs = modelBuilder.getBkgPdfs();
    modelBuilder.setSignalPdfFromMC(sigMC);
    modelBuilder.makeSBPdfs();
    map<string,RooAbsPdf*> sbPdfs = modelBuilder.getSBPdfs();

    modelBuilder.fitToData(dataBinned,true,true);
    modelBuilder.fitToData(dataBinned,false,true);

    modelBuilder.throwToy(Form("cat%d_toy0",cat),dataBinned->sumEntries(),true,true);

    // Profile this category using ProfileMultiplePdfs
    ProfileMultiplePdfs profiler;
    for (map<string,RooAbsPdf*>::iterator pdf=sbPdfs.begin(); pdf!=sbPdfs.end(); pdf++) {
      string bkgOnlyName = pdf->first.substr(pdf->first.find("sb_")+3,string::npos);
      if (bkgPdfs.find(bkgOnlyName)==bkgPdfs.end()){
        cerr << "ERROR -- couldn't find bkg only pdf " << bkgOnlyName << " for SB pdf " << pdf->first << endl;
        pdf->second->fitTo(*dataBinned);
        exit(1);
      }
      int nParams = bkgPdfs[bkgOnlyName]->getVariables()->getSize()-1;
      profiler.addPdf(pdf->second,2*nParams);
      //profiler.addPdf(pdf->second);
      cout << pdf->second->GetName() << " nParams=" << pdf->second->getVariables()->getSize() << " nBkgParams=" << nParams << endl;
    }
    profiler.printPdfs();
    //cout << "Continue?" << endl;
    //string bus; cin >> bus;
    profiler.plotNominalFits(dataBinned,mass,80,Form("cat%d",cat));
    pair<double,map<string,TGraph*> > minNlls = profiler.profileLikelihood(dataBinned,mass,mu,mu_low,mu_high,mu_step);
    pair<double,map<string,TGraph*> > correctedNlls = profiler.computeEnvelope(minNlls,Form("cat%d",cat),2.);
    minNlltrack.push_back(make_pair(correctedNlls.first,correctedNlls.second["envelope"]));
    //minNlls.second.insert(pair<string,TGraph*>("envelope",envelopeNll.second));
    //map<string,TGraph*> minNLLs = profiler.profileLikelihoodEnvelope(dataBinned,mu,mu_low,mu_high,mu_step);
    profiler.plot(correctedNlls.second,Form("cat%d_nlls",cat));
    //profiler.print(minNLLs,mu_low,mu_high,mu_step);
    /*
    if (minNLLs.find("envelope")==minNLLs.end()){
      cerr << "ERROR -- envelope TGraph not found in minNLLs" << endl;
      exit(1);
    }
    */
    //minNlltrack.push_back(make_pair(profiler.getGlobalMinNLL(),minNLLs["envelope"]));
  }
  //exit(1);
  TGraph *comb = new TGraph();
  for (vector<pair<double,TGraph*> >::iterator it=minNlltrack.begin(); it!=minNlltrack.end(); it++){
    if (it->second->GetN()!=minNlltrack.begin()->second->GetN()){
      cerr << "ERROR -- unequal number of points for TGraphs " << it->second->GetName() << " and " << minNlltrack.begin()->second->GetName() << endl;
      exit(1);
    }
  }
  for (int p=0; p<minNlltrack.begin()->second->GetN(); p++){
    double x,y,sumy=0;
    for (vector<pair<double,TGraph*> >::iterator it=minNlltrack.begin(); it!=minNlltrack.end(); it++){
      it->second->GetPoint(p,x,y);
      sumy += (y+it->first);
    }
    comb->SetPoint(p,x,sumy);
  }
  pair<double,double> globalMin = getGraphMin(comb);
  for (int p=0; p<comb->GetN(); p++){
    double x,y;
    comb->GetPoint(p,x,y);
    comb->SetPoint(p,x,y-globalMin.second);
  }
  vector<double> fitVal = getValsFromLikelihood(comb);

  cout << "Best fit.." << endl;
  cout << "\t mu = " << Form("%4.3f",fitVal[0]) << " +/- (1sig) = " << fitVal[2]-fitVal[0] << " / " << fitVal[0]-fitVal[1] << endl;
  cout << "\t      " << "    " << " +/- (2sig) = " << fitVal[4]-fitVal[0] << " / " << fitVal[0]-fitVal[3] << endl;

  cout << comb->Eval(fitVal[0]) << " " << comb->Eval(fitVal[1]) << " " << comb->Eval(fitVal[2]) << " " << comb->Eval(fitVal[3]) << " " << comb->Eval(fitVal[4]) << endl;

  double quadInterpVal = ProfileMultiplePdfs::quadInterpMinimum(comb);
  cout << "quadInterp: mu = " << quadInterpVal << endl;
  cout << "\t " << comb->Eval(quadInterpVal) << " " << comb->Eval(quadInterpVal-0.005) << " " << comb->Eval(quadInterpVal-0.01) << " " << comb->Eval(quadInterpVal+0.005) << " " << comb->Eval(quadInterpVal+0.01) << endl;
  
  comb->SetLineWidth(2);
  TCanvas *canv = new TCanvas();
  comb->Draw("ALP");
  canv->Print("plots/comb.pdf");
  TFile *tempOut = new TFile("tempOut.root","RECREATE");
  tempOut->cd();
  comb->SetName("comb");
  comb->Write();
  tempOut->Close();
  return 0;
}
Example #14
0
void plotMSSM(const TString& what="(ggA+bbA)*BRAZh*BRhbb"){
  const double BRZll=0.06726;
  const double fb2pb=1000;
  //TString scale(Form("*%f*%f",BRZll,fb2pb));
  TString scale("");

  TString cname(what);
  cname.ReplaceAll("*","x");
  cname.ReplaceAll("(","U");
  cname.ReplaceAll(")","U");
  cname+="_MSSM_mhmax";
  //
  TString goodName(what);
  goodName.ReplaceAll("mh","m_{h}");
  goodName.ReplaceAll("ggA","#sigma_{gg#rightarrowA}");
  goodName.ReplaceAll("bbA","#sigma_{bb#rightarrowA}");
  goodName.ReplaceAll("BRAZh","B(A#rightarrowZh)");
  goodName.ReplaceAll("BRhbb","B(h#rightarrowbb)");
  //goodName+=("*B(Z#rightarrowll)");
  //goodName+=("[pb] ");
  goodName+=("[GeV] ");
  TString goodType("MSSM m_{h}^{max}");
  //goodName=("#sigma*B(pp#rightarrowA#rightarrowZh#rightarrowllbb) [fb]");
  //goodName=("#sigma*B(pp#rightarrowA) [fb]");
  //goodName=("BR(A#rightarrowZh)");
  //goodName=("BR(h#rightarrowbb)");

  //if (m>0) mass=(Form(" * (mA==%d)",m));
  //TString ok(" * validity * stability * perturbativity * unitarity ");
  //TString ok(" * unitarity");
  TString ok("");


  TChain* ch=new TChain("TreeMSSM");

  ch->Add("lsf_working_dir_M225_20636539/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M250_20636540/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M275_20636541/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M300_20636542/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M325_20636543/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M350_20636544/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M400_20636545/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M500_20636546/parameter_MSSM.root");
  ch->Add("lsf_working_dir_M600_20636547/parameter_MSSM.root");

  //double tanbeta[30]={1,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,400,500,600,700,800,900,1000,1100,10000};
  //double tanbeta[51]={0,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380,400,420,440,460,480,500,550,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,2000,3000,4000,5000,6000};
  double tanbeta[51]={0,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,320,340,360,380,400,420,440,460,500,550,580,600,650,700,750,800,850,900,950,1000,1100,1200,1300,1400,1500,2000,3000,4000,5000,6000};
  Double_t bin_tb[50];
  for (unsigned int i=0; i<50; i++) {
    bin_tb[i]=0.005*(tanbeta[i]+tanbeta[i+1]);
    //cout << "bin_tb[" << i << "]=" << bin_tb[i] << " " << tanbeta[i+1]/100. << endl;
  }

  double mA[11]={200,225,250,275,300,325,350,400,500,600,700};
  Double_t bin_mA[10];
  for (unsigned int i=0; i<=10; ++i) {
    bin_mA[i]=0.5*(mA[i]+mA[i+1]);
    //cout << "bin_mA["<<i<<"]="  << bin_mA[i] << endl;
  }
  bin_mA[10]=650;
  
  TH2F* hggA=new TH2F("hggA","ggA cross section vs tan#beta,m_{A}; m_{A} GeV; tan#beta",9,bin_mA,49,bin_tb);
  hggA->Sumw2();
  //hggA->Draw();
  TString cut=what+scale+ok;
  cout << "CUT: " << cut << endl;
  ch->Project("hggA","tb:mA",cut);

  TStyle *tdrStyle = gROOT->GetStyle("tdrStyle");
  // Double_t level[15]={.01,.02,.05,.1,.2,.5,1.,2.,5.,10.,20.,50.,100.,200.,500.};
  // hggA->SetContour(14,level);
  // hggA->SetMinimum(level[0]);
  //
  //Double_t level[10]={1.,5.,10.,20.,50.,100.,200.,500.,800.,1000.}; // for x-section
  //Double_t level[10]={100,105,110.,115.,120.,123,125.7,127,130.,135.}; // for mh
  Double_t level[10]={1,2,3.,4.,120.,123,125.7,127,130.,135.}; // for mh
  //Double_t level[10]={.01,.1,.2,0.5,0.6,0.65,0.7,0.75,0.8,0.9}; // for BR
  //Double_t level[10]={.01,.02,.05,.07,.1,.15,0.2,0.5,0.75,1.}; // for BR
  hggA->SetContour(9,level);
  hggA->SetMinimum(level[0]);
  
  Double_t level[7]={122.7.,123.7,125.4,126.0,127.7,128.7.,150}; // for mh
  hggA->SetContour(6,level);
  hggA->SetMinimum(90);
  Int_t colors[7] = {kWhite,kGreen,kGreen+2,kBlack,kGreen+2,kGreen,kWhite};
  tdrStyle->SetPalette((sizeof(colors)/sizeof(Int_t)), colors);

// DRAW
  tdrStyle->SetOptStat(0);
  // tdrStyle->SetPadGridX(true);
  // tdrStyle->SetPadGridY(true);
  // tdrStyle->SetPadTopMargin(0.05);
  // tdrStyle->SetPadBottomMargin(0.13);
  tdrStyle->SetTitleYOffset(1.3);
  tdrStyle->SetTitleXOffset(1.6);
  tdrStyle->SetTitleOffset(1.3,"Z");
  // tdrStyle->SetOptLogz(1);
  // tdrStyle->SetOptLogy(1);
  tdrStyle->SetPadRightMargin(0.14);
  //tdrStyle->SetPalette(1);


  tdrStyle->cd();
  gROOT->ForceStyle();

  cout << "Creating canvas " << cname << endl;
  TCanvas* c1=new TCanvas(cname,goodName,1200,600);
  cout << " done " << c1->GetName() << endl;
  c1->Divide(2);

  c1->cd(1);
  hggA->DrawCopy("lego2");
  gPad->SetLogz();
  gPad->SetLogy();
  //gPad->SetPhi(120);
  gPad->SetPhi(-150);
  //gPad->SetTheta(30);
  gPad->UseCurrentStyle();
  gPad->Update();

  TLatex tl;
  tl.SetTextSize(0.04);
  tl.SetNDC();
  tl.DrawLatex(0.1,0.95,goodName);
  tl.SetTextAlign(11);
  tl.DrawLatex(0.1,0.89,goodType);

  c1->cd(2);
 // tdrStyle->SetPadLeftMargin(0.25);

  gPad->UseCurrentStyle();
  gPad->Update();
  hggA->GetXaxis()->SetTitleOffset(1.1);
  hggA->GetYaxis()->SetTitleOffset(1.1);
  hggA->GetZaxis()->SetTitleOffset(100);
  //hggA->Smooth();
  gPad->SetLogy(kFALSE);
  hggA->DrawCopy("zcont1");
  tl.DrawLatex(0.15,0.97,goodName);
  tl.SetTextAlign(11);
  tl.DrawLatex(0.2,0.9,goodType);

  TCanvas* ctmp=new TCanvas(cname,goodName,600,600);
  hggA->GetYaxis()->SetRangeUser(0.1,10.);
  hggA->DrawCopy("zcont1");
  tl.DrawLatex(0.83,0.97,goodName);
  tl.SetTextAlign(11);
  tl.DrawLatex(0.2,0.9,goodType);
  pCan(ctmp,cname+"_Lin");

  // TH1F* test=new TH1F("test","ggA cross section vs tan#beta; tan#beta",27,bin_tb);
  // ch->Project("test","tb",what);
  // test->Draw();


  TCanvas* c2=new TCanvas(cname+"Obs",goodName,800,800);
  gPad->UseCurrentStyle();
  gPad->Update();
  hggA->GetXaxis()->SetTitleOffset(1.1);
  hggA->GetYaxis()->SetTitleOffset(1.1);
  hggA->DrawCopy("cont list");
  gPad->Update();

  //return;
  // Get Contours
   TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
   TList* contLevel = NULL;
   TGraph* curv     = NULL;
   TGraph* gc       = NULL;

   Int_t nGraphs    = 0;
   Int_t TotalConts = 0;

   if (conts == NULL){
      printf("*** No Contours Were Extracted!\n");
      TotalConts = 0;
      return;
   } else {
      TotalConts = conts->GetSize();
   }

   printf("TotalConts = %d\n", TotalConts);

   for(i = 0; i < TotalConts; i++){
      contLevel = (TList*)conts->At(i);
      printf("Contour %d has %d Graphs\n", i, contLevel->GetSize());
      nGraphs += contLevel->GetSize();
   }

   nGraphs = 0;

   TH2F *hr = new TH2F("hr", ";m_{A};tan#beta", 2, 225, 600, 2, 0.1, 100);

   hr->GetXaxis()->SetTitleOffset(1.1);
   hr->GetXaxis()->SetRangeUser(200,650);
   hr->GetYaxis()->SetTitleOffset(1.2);
   hr->GetYaxis()->SetNdivisions(110,kFALSE);
   hr->GetXaxis()->SetNdivisions(20205,kFALSE);
   hr->Draw();
   Double_t x0, y0, z0;
   TLatex l;
   l.SetTextSize(0.03);
   l.SetTextAlign(32);
   char val[20];

   for(i = 0; i < TotalConts; i++){
      contLevel = (TList*)conts->At(i);
      z0 = level[i];
      printf("Z-Level Passed in as:  Z = %f\n", z0);

      // Get first graph from list on curves on this level
      curv = (TGraph*)contLevel->First();
      for(j = 0; j < contLevel->GetSize(); j++){
        // last point
         //curv->GetPoint(curv->GetN()-1, x0, y0);
        // first point
         curv->GetPoint(2, x0, y0);

         // if (z0<0) curv->SetLineColor(kRed);
         // if (z0>0) curv->SetLineColor(kBlue);
         nGraphs ++;
         printf("\tGraph: %d  -- %d Elements\n", nGraphs,curv->GetN());

	 // Draw clones of the graphs to avoid deletions in case the 1st
	 // pad is redrawn.
         gc = (TGraph*)curv->Clone();
         gc->Draw("C");

         if (z0>=.01) sprintf(val,"%0.2f",z0);
         if (z0>=.1) sprintf(val,"%0.2f",z0);
         if (z0>=1) sprintf(val,"%0.0f",z0);
         l.DrawLatex(x0*0.99,y0,val);
         curv = (TGraph*)contLevel->After(curv); // Get Next graph
      }
   }
   gPad->SetLogy();
   gPad->SetGridx();
   gPad->SetGridy();
   gPad->SetRightMargin(0.05);
   gPad->SetTopMargin(0.10);
   c2->Update();
   printf("\n\n\tExtracted %d Contours and %d Graphs \n", TotalConts, nGraphs );



  tl.SetTextAlign(31);
  tl.DrawLatex(0.8,0.85,goodName);

  tl.SetTextAlign(31);
  tl.DrawLatex(0.8,0.77,goodType);


  pCan(c2,cname+"_BW");

   c1->cd(1);
   gPad->SetLogy();
   gPad->SetLogz();
   c1->cd(2);
   gPad->SetLogy();
   c1->Update();
  pCan(c1,cname);
}
Example #15
0
TCanvas *ContourList(){

   const Double_t PI = TMath::Pi();

   TCanvas* c = new TCanvas("c","Contour List",0,0,600,600);
   c->SetRightMargin(0.15);
   c->SetTopMargin(0.15);

   Int_t i, j, TotalConts;

   Int_t nZsamples   = 80;
   Int_t nPhiSamples = 80;

   Double_t HofZwavelength = 4.0;       // 4 meters
   Double_t dZ             =  HofZwavelength/(Double_t)(nZsamples - 1);
   Double_t dPhi           = 2*PI/(Double_t)(nPhiSamples - 1);

   TArrayD z(nZsamples);
   TArrayD HofZ(nZsamples);
   TArrayD phi(nPhiSamples);
   TArrayD FofPhi(nPhiSamples);

   // Discretized Z and Phi Values
   for ( i = 0; i < nZsamples; i++) {
      z[i] = (i)*dZ - HofZwavelength/2.0;
      HofZ[i] = SawTooth(z[i], HofZwavelength);
   }

   for(Int_t i=0; i < nPhiSamples; i++){
      phi[i] = (i)*dPhi;
      FofPhi[i] = sin(phi[i]);
   }

   // Create Histogram
   TH2D *HistStreamFn = new TH2D("HstreamFn",
   "#splitline{Histogram with negative and positive contents. Six contours are defined.}{It is plotted with options CONT LIST to retrieve the contours points in TGraphs}",
   nZsamples, z[0], z[nZsamples-1], nPhiSamples, phi[0], phi[nPhiSamples-1]);

   // Load Histogram Data
   for (Int_t i = 0; i < nZsamples; i++) {
      for(Int_t j = 0; j < nPhiSamples; j++){
         HistStreamFn->SetBinContent(i,j, HofZ[i]*FofPhi[j]);
      }
   }

   gStyle->SetPalette(1);
   gStyle->SetOptStat(0);
   gStyle->SetTitleW(0.99);
   gStyle->SetTitleH(0.08);

   Double_t contours[6];
   contours[0] = -0.7;
   contours[1] = -0.5;
   contours[2] = -0.1;
   contours[3] =  0.1;
   contours[4] =  0.4;
   contours[5] =  0.8;

   HistStreamFn->SetContour(6, contours);

   // Draw contours as filled regions, and Save points
   HistStreamFn->Draw("CONT Z LIST");
   c->Update(); // Needed to force the plotting and retrieve the contours in TGraphs

   // Get Contours
   TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
   TList* contLevel = NULL;
   TGraph* curv     = NULL;
   TGraph* gc       = NULL;

   Int_t nGraphs    = 0;
   Int_t TotalConts = 0;

   if (conts == NULL){
      printf("*** No Contours Were Extracted!\n");
      TotalConts = 0;
      return;
   } else {
      TotalConts = conts->GetSize();
   }

   printf("TotalConts = %d\n", TotalConts);

   for(i = 0; i < TotalConts; i++){
      contLevel = (TList*)conts->At(i);
      printf("Contour %d has %d Graphs\n", i, contLevel->GetSize());
      nGraphs += contLevel->GetSize();
   }

   nGraphs = 0;

   TCanvas* c1 = new TCanvas("c1","Contour List",610,0,600,600);
   c1->SetTopMargin(0.15);
   TH2F *hr = new TH2F("hr",
   "#splitline{Negative contours are returned first (highest to lowest). Positive contours are returned from}{lowest to highest. On this plot Negative contours are drawn in red and positive contours in blue.}",
   2, -2, 2, 2, 0, 6.5);

   hr->Draw();
   Double_t x0, y0, z0;
   TLatex l;
   l.SetTextSize(0.03);
   char val[20];

   for(i = 0; i < TotalConts; i++){
      contLevel = (TList*)conts->At(i);
      if (i<3) z0 = contours[2-i];
      else     z0 = contours[i];
      printf("Z-Level Passed in as:  Z = %f\n", z0);

      // Get first graph from list on curves on this level
      curv = (TGraph*)contLevel->First();
      for(j = 0; j < contLevel->GetSize(); j++){
         curv->GetPoint(0, x0, y0);
         if (z0<0) curv->SetLineColor(kRed);
         if (z0>0) curv->SetLineColor(kBlue);
         nGraphs ++;
         printf("\tGraph: %d  -- %d Elements\n", nGraphs,curv->GetN());

	 // Draw clones of the graphs to avoid deletions in case the 1st
	 // pad is redrawn.
         gc = (TGraph*)curv->Clone();
         gc->Draw("C");

         sprintf(val,"%g",z0);
         l.DrawLatex(x0,y0,val);
         curv = (TGraph*)contLevel->After(curv); // Get Next graph
      }
   }
   c1->Update();
   printf("\n\n\tExtracted %d Contours and %d Graphs \n", TotalConts, nGraphs );
   gStyle->SetTitleW(0.);
   gStyle->SetTitleH(0.);
   return c1;
}
Example #16
0
///
/// Make a plot out of a 1D histogram holding a 1-CL curve.
/// The strategy is to always convert the 1-CL histogram (hCL) into
/// a TGraph. This way we can add known points (solutions, points
/// at end of scan range) and also have a filled area without line
/// smoothing. This is not possible with histograms due to a Root bug.
///
/// The function draws the TGraphs, and returns a pointer to the
/// TGraph object that can be used in the TLegend.
///
/// Markers are plotted if the method name of the scanner is "Plugin" or "BergerBoos" or "DatasetsPlugin".
/// One can plot a line instead of points even for the Plugin method by
/// using setPluginMarkers().
///
/// For the angle variables, a new axis is painted that is in Deg.
///
/// \param s The scanner to plot.
/// \param first
/// \param last
/// \param filled
///
TGraph* OneMinusClPlot::scan1dPlot(MethodAbsScan* s, bool first, bool last, bool filled, int CLsType)
{
	if ( arg->debug ){
		cout << "OneMinusClPlot::scan1dPlot() : plotting ";
		cout << s->getName() << " (" << s->getMethodName() << ")" << endl;
	}
	if ( m_mainCanvas==0 ){
		m_mainCanvas = newNoWarnTCanvas(name+getUniqueRootName(), title, 800, 600);
	}
	m_mainCanvas->cd();
	bool plotPoints = ( s->getMethodName()=="Plugin" || s->getMethodName()=="BergerBoos" || s->getMethodName()=="DatasetsPlugin" ) && plotPluginMarkers;
	TH1F *hCL = (TH1F*)s->getHCL()->Clone(getUniqueRootName());
	if (CLsType==1) hCL = (TH1F*)s->getHCLs()->Clone(getUniqueRootName());
  else if (CLsType==2) hCL = (TH1F*)s->getHCLsFreq()->Clone(getUniqueRootName());
	// fix inf and nan entries
	for ( int i=1; i<=s->getHCL()->GetNbinsX(); i++ ){
		if ( s->getHCL()->GetBinContent(i)!=s->getHCL()->GetBinContent(i)
				|| std::isinf(s->getHCL()->GetBinContent(i)) ) s->getHCL()->SetBinContent(i, 0.0);
	}

	// remove errors the hard way, else root ALWAYS plots them
	if ( !plotPoints ) hCL = histHardCopy(hCL, true, true);

	// disable any statistics box
	hCL->SetStats(0);

	// Convert the histogram into a TGraph so we can add the solution.
	// Also, the lf2 drawing option is broken in latest root versions.
	TGraph *g;
	if ( plotPoints ) g = new TGraphErrors(hCL->GetNbinsX());
	else              g = new TGraph(hCL->GetNbinsX());
	g->SetName(getUniqueRootName());
	for ( int i=0; i<hCL->GetNbinsX(); i++ ){
		g->SetPoint(i, hCL->GetBinCenter(i+1), hCL->GetBinContent(i+1));
		if ( plotPoints ) ((TGraphErrors*)g)->SetPointError(i, 0.0, hCL->GetBinError(i+1));
	}

	// add solution
	if ( ! s->getSolutions().empty() ){
		TGraphTools t;
		TGraph *gNew = t.addPointToGraphAtFirstMatchingX(g, s->getScanVar1Solution(0), 1.0);
		delete g;
		g = gNew;
	}

	// // set last point to the same p-value as first point by hand
	// // some angle plots sometimes don't manage to do it by themselves...
	// if ( arg->isQuickhack(XX) )
	// {
	//   Double_t pointx0, pointy0, err0;
	//   Double_t pointx1, pointy1, err1;
	//   g->GetPoint(0, pointx0, pointy0);
	//   g->GetPoint(g->GetN()-1, pointx1, pointy1);
	//   g->SetPoint(g->GetN()-1, pointx1, pointy0);
	//   if ( plotPoints ) err0 = ((TGraphErrors*)g)->GetErrorY(0);
	//   if ( plotPoints ) ((TGraphErrors*)g)->SetPointError(g->GetN()-1, 0.0, err0);
	// }

	// add end points of scan range
	if ( !plotPoints )
	{
		Double_t pointx0, pointy0;
		TGraph *gNew = new TGraph(g->GetN()+4);
		gNew->SetName(getUniqueRootName());
		for ( int i=0; i<g->GetN(); i++)
		{
			g->GetPoint(i, pointx0, pointy0);
			gNew->SetPoint(i+2, pointx0, pointy0);
		}

		// add origin
		gNew->SetPoint(0, hCL->GetXaxis()->GetXmin(), 0);

		// add a point at first y height but at x=origin.
		g->GetPoint(0, pointx0, pointy0);
		gNew->SetPoint(1, hCL->GetXaxis()->GetXmin(), pointy0);

		// add a point at last y height but at x=xmax.
		g->GetPoint(g->GetN()-1, pointx0, pointy0);
		gNew->SetPoint(gNew->GetN()-2, hCL->GetXaxis()->GetXmax(), pointy0);

		// add a point at xmax, 0
		gNew->SetPoint(gNew->GetN()-1, hCL->GetXaxis()->GetXmax(), 0);
		g = gNew;
	}

	int color = s->getLineColor();
	if(CLsType>0 && s->getMethodName().Contains("Plugin") && !arg->plotpluginonly) {
    if (CLsType==1) color = kBlue-7;
    else if (CLsType==2) color = kBlue+2;
  }
	else if(CLsType>0) {
    if (CLsType==1) color = s->getLineColor() - 5;
    if (CLsType==2) color = s->getLineColor() - 4;
  }
	g->SetLineColor(color);

	if ( filled ){
		g->SetLineWidth(2);
    double alpha = arg->isQuickhack(12) ? 0.4 : 1.;
    if ( arg->isQuickhack(24) ) alpha = 0.;
		g->SetFillColorAlpha(color,alpha);
		g->SetLineStyle(1);
    g->SetFillStyle( s->getFillStyle() );
	}
	else{
		g->SetLineWidth(2);
		g->SetLineStyle(s->getLineStyle());
    if ( last && arg->isQuickhack(25) ) g->SetLineWidth(3);
	}

	if ( plotPoints ){
		g->SetLineWidth(1);
		g->SetMarkerColor(color);
		g->SetMarkerStyle(8);
		g->SetMarkerSize(0.6);
		if(CLsType==1) {
			g->SetMarkerStyle(33);
			g->SetMarkerSize(1);
		}
		if(CLsType==2) {
			g->SetMarkerStyle(21);
		}
	}

	// build a histogram which holds the axes
	float min = arg->scanrangeMin == arg->scanrangeMax ? hCL->GetXaxis()->GetXmin() : arg->scanrangeMin;
	float max = arg->scanrangeMin == arg->scanrangeMax ? hCL->GetXaxis()->GetXmax() : arg->scanrangeMax;
	TH1F *haxes = new TH1F("haxes"+getUniqueRootName(), "", 100, min, max);
	haxes->SetStats(0);
	haxes->GetXaxis()->SetTitle(s->getScanVar1()->GetTitle());
	haxes->GetYaxis()->SetTitle("1-CL");
	haxes->GetXaxis()->SetLabelFont(font);
	haxes->GetYaxis()->SetLabelFont(font);
	haxes->GetXaxis()->SetTitleFont(font);
	haxes->GetYaxis()->SetTitleFont(font);
	haxes->GetXaxis()->SetTitleOffset(0.9);
	haxes->GetYaxis()->SetTitleOffset(0.85);
	haxes->GetXaxis()->SetLabelSize(labelsize);
	haxes->GetYaxis()->SetLabelSize(labelsize);
	haxes->GetXaxis()->SetTitleSize(titlesize);
	haxes->GetYaxis()->SetTitleSize(titlesize);
	int xndiv = arg->ndiv==-1 ? 407 : abs(arg->ndiv);
	bool optimizeNdiv = arg->ndiv<0 ? true : false;
	haxes->GetXaxis()->SetNdivisions(xndiv, optimizeNdiv);
	haxes->GetYaxis()->SetNdivisions(407, true);

  // plot y range
  float plotYMax;
  float plotYMin;
  if ( plotLegend && !arg->isQuickhack(22) ) {
    if ( arg->plotlog ) { plotYMin = 1.e-3; plotYMax = 10.; }
    else                { plotYMin = 0.0  ; plotYMax = 1.3; }
  }
  else {
    if ( arg->plotlog ) { plotYMin = 1.e-3; plotYMax = 1.0; }
    else                { plotYMin = 0.0  ; plotYMax = 1.0; }
  }
  // change if passed as option
	plotYMin = arg->plotymin > 0. ? arg->plotymin : plotYMin;
  plotYMax = arg->plotymax > 0. ? arg->plotymax : plotYMax;

  haxes->GetYaxis()->SetRangeUser( plotYMin, plotYMax );
	haxes->Draw("axissame");
	g->SetHistogram(haxes);

	TString drawOption = "";
	if ( plotPoints )   drawOption += " pe";
	else if ( filled )  drawOption += " F";
	else                drawOption += " L";
	if ( first )        drawOption += " A";
	g->Draw(drawOption);
  //if ( drawOption.Contains("F") ) ((TGraph*)g->Clone())->Draw("L");

	gPad->Update();
	float ymin = gPad->GetUymin();
	float ymax = gPad->GetUymax();
	float xmin = gPad->GetUxmin();
	float xmax = gPad->GetUxmax();

	// for the angles, draw a new axis in units of degrees
	if ( isAngle(s->getScanVar1()) ){
		haxes->GetXaxis()->SetTitle(s->getScanVar1()->GetTitle() + TString(" [#circ]"));
		haxes->GetXaxis()->SetNdivisions(0);  // disable old axis
		if ( last ){
			// new top axis
			TString chopt = "-U"; // - = downward ticks, U = unlabeled, http://root.cern.ch/root/html534/TGaxis.html
			if ( !optimizeNdiv ) chopt += "N"; // n = no bin optimization
			TGaxis *axist = new TGaxis(xmin, 1, xmax, 1, RadToDeg(xmin), RadToDeg(xmax), xndiv, chopt);
			axist->SetName("axist");
			axist->Draw();

			// new bottom axis
			float axisbMin = RadToDeg(xmin);
			float axisbMax = RadToDeg(xmax);
			if ( arg->isQuickhack(3) ){ ///< see documentation of --qh option in OptParser.cpp
				axisbMin += 180.;
				axisbMax += 180.;
			}
			chopt = ""; // - = downward ticks, U = unlabeled, http://root.cern.ch/root/html534/TGaxis.html
			if ( !optimizeNdiv ) chopt += "N"; // n = no bin optimization
			TGaxis *axisb = new TGaxis(xmin, ymin, xmax, ymin, axisbMin, axisbMax, xndiv, chopt);
			axisb->SetName("axisb");
			axisb->SetLabelFont(font);
			axisb->SetLabelSize(labelsize);
			axisb->Draw();
		}
	}
	else
	{
		if ( last ){
			// add top axis
			TString chopt = "-U"; // - = downward ticks, U = unlabeled, http://root.cern.ch/root/html534/TGaxis.html
			if ( !optimizeNdiv ) chopt += "N"; // n = no bin optimization
			TGaxis *axist = new TGaxis(xmin, 1.0, xmax, 1.0, xmin, xmax, xndiv, chopt);
			axist->SetName("axist");
			axist->SetLineWidth(1);
			axist->Draw();
		}
	}

	if ( last )
	{
		// add right axis
		TGaxis *axisr = 0;
		if ( arg->plotlog ){
			float f3min = 1e-3;
			float f3max = (plotLegend && !arg->isQuickhack(22)) ? 10. : 1.;
			TF1 *f3 = new TF1("f3","log10(x)",f3min,f3max);
			axisr = new TGaxis(xmax, f3min, xmax, f3max, "f3", 510, "G+");
		}
		else{
			axisr = new TGaxis(xmax, ymin, xmax, ymax, 0, (plotLegend && !arg->isQuickhack(22)) ? 1.3 : 1.0, 407, "+");
		}
		axisr->SetLabelSize(0);
		axisr->SetLineWidth(1);
		axisr->SetName("axisr");
		axisr->SetLabelColor(kWhite);
		axisr->SetTitleColor(kWhite);
		axisr->Draw();

		// redraw right axis as well because the 1-CL graph can cover the old one
		haxes->Draw("axissame");
	}

	return g;
}
Example #17
0
///
/// Make a plot for the CLs stuff.
/// The strategy is to convert the hCLExp and hCLErr histogrms
/// into TGraphs and TGraphAsymmErrors
/// We can then provide some smoothing options as well
///
/// \param s The scanner to plot.
/// \param smooth
///
void OneMinusClPlot::scan1dCLsPlot(MethodAbsScan *s, bool smooth, bool obsError)
{
  if ( arg->debug ){
    cout << "OneMinusClPlot::scan1dCLsPlot() : plotting ";
    cout << s->getName() << " (" << s->getMethodName() << ")" << endl;
  }
  m_mainCanvas->cd();

  s->checkCLs();

  TH1F *hObs    = (TH1F*)s->getHCLsFreq()->Clone(getUniqueRootName());
  TH1F *hExp    = (TH1F*)s->getHCLsExp()->Clone(getUniqueRootName());
  TH1F *hErr1Up = (TH1F*)s->getHCLsErr1Up()->Clone(getUniqueRootName());
  TH1F *hErr1Dn = (TH1F*)s->getHCLsErr1Dn()->Clone(getUniqueRootName());
  TH1F *hErr2Up = (TH1F*)s->getHCLsErr2Up()->Clone(getUniqueRootName());
  TH1F *hErr2Dn = (TH1F*)s->getHCLsErr2Dn()->Clone(getUniqueRootName());

  if ( !hObs ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - can't find histogram hObs" << endl;
  if ( !hExp ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - can't find histogram hExp" << endl;
  if ( !hErr1Up ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - can't find histogram hErr1Up" << endl;
  if ( !hErr1Dn ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - can't find histogram hErr1Dn" << endl;
  if ( !hErr2Up ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - can't find histogram hErr2Up" << endl;
  if ( !hErr2Dn ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - can't find histogram hErr2Dn" << endl;

  // convert obs to graph
  TGraph *gObs = convertTH1ToTGraph(hObs,obsError);

  // convert others to raw graphs
  TGraph *gExpRaw    = convertTH1ToTGraph(hExp);
  TGraph *gErr1UpRaw = convertTH1ToTGraph(hErr1Up);
  TGraph *gErr1DnRaw = convertTH1ToTGraph(hErr1Dn);
  TGraph *gErr2UpRaw = convertTH1ToTGraph(hErr2Up);
  TGraph *gErr2DnRaw = convertTH1ToTGraph(hErr2Dn);

  // smoothing if needed
  TGraph *gExp;
  TGraph *gErr1Up;
  TGraph *gErr1Dn;
  TGraph *gErr2Up;
  TGraph *gErr2Dn;

  TGraphSmooth *smoother = new TGraphSmooth();
  if (smooth) {
    if ( arg->debug ) cout << "OneMinusClPlot::scan1dCLsPlot() : smoothing graphs" << endl;
    gExp    = (TGraph*)smoother->SmoothSuper( gExpRaw    )->Clone("gExp");
    gErr1Up = (TGraph*)smoother->SmoothSuper( gErr1UpRaw )->Clone("gErr1Up");
    gErr1Dn = (TGraph*)smoother->SmoothSuper( gErr1DnRaw )->Clone("gErr1Dn");
    gErr2Up = (TGraph*)smoother->SmoothSuper( gErr2UpRaw )->Clone("gErr2Up");
    gErr2Dn = (TGraph*)smoother->SmoothSuper( gErr2DnRaw )->Clone("gErr2Dn");
    if ( arg->debug ) cout << "OneMinusClPlot::scan1dCLsPlot() : done smoothing graphs" << endl;
  }
  else {
    gExp    = gExpRaw;
    gErr1Up = gErr1UpRaw;
    gErr1Dn = gErr1DnRaw;
    gErr2Up = gErr2UpRaw;
    gErr2Dn = gErr2DnRaw;
  }

  if ( !gObs ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - null graph gObs" << endl;
  if ( !gExp ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - null graph gExp" << endl;
  if ( !gErr1Up ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - null graph gErr1Up" << endl;
  if ( !gErr1Dn ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - null graph gErr1Dn" << endl;
  if ( !gErr2Up ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - null graph gErr2Up" << endl;
  if ( !gErr2Dn ) cout << "OneMinusClPlot::scan1dCLsPlot() : problem - null graph gErr2Dn" << endl;

  gObs->SetName("gObs");
  gExp->SetName("gExp");
  gErr1Up->SetName("gErr1Up");
  gErr1Dn->SetName("gErr1Dn");
  gErr2Up->SetName("gErr2Up");
  gErr2Dn->SetName("gErr2Dn");

  // now make the graphs for the error bands
  TGraphAsymmErrors *gErr1 = new TGraphAsymmErrors( gExp->GetN() );
  gErr1->SetName("gErr1");
  TGraphAsymmErrors *gErr2 = new TGraphAsymmErrors( gExp->GetN() );
  gErr2->SetName("gErr2");

  double x,y,yerrUp,yerrDn;
  double xerr = (hExp->GetBinCenter(2)-hExp->GetBinCenter(1))/2.;

  // protect against smoothing over 1
  for (int i=0; i<gExp->GetN(); i++) {
    gExp->GetPoint(i,x,y); gExp->SetPoint(i,x,TMath::Min(y,1.));
    gErr1Up->GetPoint(i,x,y); gErr1Up->SetPoint(i,x,TMath::Min(y,1.));
    gErr1Dn->GetPoint(i,x,y); gErr1Dn->SetPoint(i,x,TMath::Min(y,1.));
    gErr2Up->GetPoint(i,x,y); gErr2Up->SetPoint(i,x,TMath::Min(y,1.));
    gErr2Dn->GetPoint(i,x,y); gErr2Dn->SetPoint(i,x,TMath::Min(y,1.));
  }

  for (int i=0; i<gExp->GetN(); i++) {
    gExp->GetPoint(i,x,y);
    gErr1->SetPoint(i,x,y);
    gErr2->SetPoint(i,x,y);

    gErr1Up->GetPoint(i,x,yerrUp);
    gErr1Dn->GetPoint(i,x,yerrDn);
    gErr1->SetPointError(i, xerr, xerr, y-yerrDn, yerrUp-y );

    gErr2Up->GetPoint(i,x,yerrUp);
    gErr2Dn->GetPoint(i,x,yerrDn);
    gErr2->SetPointError(i, xerr, xerr, y-yerrDn, yerrUp-y );
  }

  gErr2->SetFillColor( TColor::GetColor("#3182bd") );
  gErr2->SetLineColor( TColor::GetColor("#3182bd") );
  gErr1->SetFillColor( TColor::GetColor("#9ecae1") );
  gErr1->SetLineColor( TColor::GetColor("#9ecae1") );
  gExp->SetLineColor(kRed);
  gExp->SetLineWidth(3);
  gObs->SetLineColor(kBlack);
  gObs->SetMarkerColor(kBlack);
  gObs->SetLineWidth(3);
  gObs->SetMarkerSize(1);
  gObs->SetMarkerStyle(20);

	float min = arg->scanrangeMin == arg->scanrangeMax ? hObs->GetXaxis()->GetXmin() : arg->scanrangeMin;
	float max = arg->scanrangeMin == arg->scanrangeMax ? hObs->GetXaxis()->GetXmax() : arg->scanrangeMax;
	TH1F *haxes = new TH1F("haxes"+getUniqueRootName(), "", 100, min, max);
	haxes->SetStats(0);
	haxes->GetXaxis()->SetTitle(s->getScanVar1()->GetTitle());
	haxes->GetYaxis()->SetTitle("CL_{S}");
	haxes->GetXaxis()->SetLabelFont(font);
	haxes->GetYaxis()->SetLabelFont(font);
	haxes->GetXaxis()->SetTitleFont(font);
	haxes->GetYaxis()->SetTitleFont(font);
	haxes->GetXaxis()->SetTitleOffset(0.9);
	haxes->GetYaxis()->SetTitleOffset(0.85);
	haxes->GetXaxis()->SetLabelSize(labelsize);
	haxes->GetYaxis()->SetLabelSize(labelsize);
	haxes->GetXaxis()->SetTitleSize(titlesize);
	haxes->GetYaxis()->SetTitleSize(titlesize);
	int xndiv = arg->ndiv==-1 ? 407 : abs(arg->ndiv);
	bool optimizeNdiv = arg->ndiv<0 ? true : false;
	haxes->GetXaxis()->SetNdivisions(xndiv, optimizeNdiv);
	haxes->GetYaxis()->SetNdivisions(407, true);
  haxes->GetYaxis()->SetRangeUser(0.,1.);

  // Legend:
	// make the legend short, the text will extend over the boundary, but the symbol will be shorter
  float legendXmin = 0.68 ;
  float legendYmin = 0.58 ;
  float legendXmax = legendXmin + 0.25 ;
  float legendYmax = legendYmin + 0.22 ;
	TLegend* leg = new TLegend(legendXmin,legendYmin,legendXmax,legendYmax);
	leg->SetFillColor(kWhite);
	leg->SetFillStyle(0);
	leg->SetLineColor(kWhite);
	leg->SetBorderSize(0);
	leg->SetTextFont(font);
	leg->SetTextSize(legendsize*0.75);

  if (obsError) leg->AddEntry( gObs, "Observed", "LEP" );
  else          leg->AddEntry( gObs, "Observed", "LP"  );
  leg->AddEntry( gExp, "Expected", "L" );
  leg->AddEntry( gErr1, "#pm 1#sigma", "F");
  leg->AddEntry( gErr2, "#pm 2#sigma", "F");

  haxes->Draw("AXIS+");
  gErr2->Draw("E3same");
  gErr1->Draw("E3same");
  gExp->Draw("Lsame");
  if (obsError) gObs->Draw("LEPsame");
  else          gObs->Draw("LPsame");
  leg->Draw("same");

  drawCLguideLine(0.1);

  double yGroup = 0.83;
  if ( arg->plotprelim || arg->plotunoff ) yGroup = 0.8;
  drawGroup(yGroup);

  m_mainCanvas->SetTicks();
  m_mainCanvas->RedrawAxis();
  m_mainCanvas->Update();
  m_mainCanvas->Modified();
  m_mainCanvas->Show();
  savePlot( m_mainCanvas, name+"_cls"+arg->plotext );
  m_mainCanvas->SetTicks(false);
}
Example #18
0
void createNNLOplot(TString theory="ahrens")
{
  // theory="ahrens", "kidonakis"
  TString outputRootFile="test.root";
  // NB: add new datset name here
  if(theory.Contains("ahrens")   ){
    outputRootFile="AhrensNLONNLL";
    //if(theory.Contains("mtt")    ) outputRootFile+="mttbar" ;
    //else if(theory.Contains("pt")) outputRootFile+="pTttbar";
    outputRootFile+=".root";
  }
  else if(theory=="kidonakis") outputRootFile="KidonakisAproxNNLO.root";
  // general options
  gStyle->SetOptStat(0);
  bool usequad=true;
  bool divideByBinwidth=true;
  // list of variables
  std::vector<TString> xSecVariables_, xSecLabel_;
  // NB: add variables for new datset name here
  TString xSecVariablesUsedAhrens[]    ={"ttbarMass", "ttbarPt"};
  TString xSecVariablesUsedKidonakis[] ={"topPt"    , "topY"   };
  if(     theory.Contains("ahrens")   ) xSecVariables_ .insert( xSecVariables_.begin(), xSecVariablesUsedAhrens   , xSecVariablesUsedAhrens    + sizeof(xSecVariablesUsedAhrens   )/sizeof(TString) );
  else if(theory=="kidonakis") xSecVariables_ .insert( xSecVariables_.begin(), xSecVariablesUsedKidonakis, xSecVariablesUsedKidonakis + sizeof(xSecVariablesUsedKidonakis)/sizeof(TString) );
  // get variable binning used for final cross sections 
  std::map<TString, std::vector<double> > bins_=makeVariableBinning();
  //std::vector<double> tempbins_;
  //double ttbarMassBins[]={345,445,545,745, 1045};
  //tempbins_.insert( tempbins_.begin(), ttbarMassBins, ttbarMassBins + sizeof(ttbarMassBins)/sizeof(double) );
  //bins_["ttbarMass"]=tempbins_;

  // loop all variables
  for(unsigned var=0; var<xSecVariables_.size(); ++var){
    TString variable=xSecVariables_[var];
    std::cout << "----------" << std::endl;
    std::cout << theory << ": " << variable << std::endl;
    // get bin boundaries
    double low =bins_[variable][0];
    double high=bins_[variable][bins_[variable].size()-1];
    // --------------------------
    // get raw nnlo theory points
    // --------------------------
    // NB: add new datset file names here
    TGraph * rawHist;
    TString predictionfolder="/afs/naf.desy.de/group/cms/scratch/tophh/CommonFiles/";
    if(theory=="ahrens"   ){
      if(variable.Contains("ttbarMass")) rawHist= new TGraph(predictionfolder+"AhrensTheory_Mttbar_8000_172.5_NLONNLL_norm.dat");//AhrensTheory_Mtt_7000_172.5_Mtt_fin.dat
      if(variable.Contains("ttbarPt"  )) rawHist= new TGraph(predictionfolder+"AhrensTheory_pTttbar_8000_172.5_NLONNLL_abs.dat");//AhrensTheory_pTttbar_7000_172.5_NLONNLL_abs.dat
    }
    else if(theory=="kidonakis"){
      if(variable.Contains("topPt")) rawHist= new TGraph(predictionfolder+"pttopnnloapprox8lhc173m.dat");//"ptnormalNNLO7lhc173m.dat" //"pttopnnloapprox8lhc173m.dat"
      if(variable.Contains("topY" )) rawHist= new TGraph(predictionfolder+"ytopnnloapprox8lhc173m.dat" );//"ynormalNNLO7lhc173m.dat"  //"ytopnnloapprox8lhc173m.dat"
    }
    // NB: say if points should be interpreted as single points with 
    //     nothing in between or as integrated value over the range
    bool points=true;
    if(theory.Contains("ahrens")) points=false;
    else if(theory=="kidonakis")  points=true;
    std::cout << "input: " << rawHist->GetTitle() << std::endl;
    std::cout << "interprete values as points?: " << points << std::endl;

    // --------------------
    // convertion to TH1F*
    // --------------------
    double *Xvalues = rawHist->GetX();
    int Nbins=rawHist->GetN();
    //double *Yvalues = rawHist->GetY(); // not working
    double xmax=-1;
    double xmin=-1;
    double binwidth=-1;
    //
    TH1F* hist;
    // NB: add additional binning for new theory here
    // NB: if loaded data should be interpreted as points with 
    //     nothing in between (like kidonakis), make suree you 
    //     choose a binning that is fine enough for the 
    //     data points loaded
    if(theory=="ahrens"){
      if(variable.Contains("ttbarMass")){
	xmin= 345.;
	xmax=2720.;
	binwidth=25.;// 5 for 8TeV, 25 for 7TeV
	if(TString(rawHist->GetTitle()).Contains("8000")) binwidth=5.;
      }
      else if(variable.Contains("ttbarPt")){
	xmin= 0.;
	xmax=1300.;
	binwidth=5.;
      }
    }
    else if(theory=="kidonakis"){ 
      if(variable.Contains("topPt")){
	xmin=   0.;
	xmax=1500.;
	binwidth=1.;
      }
      else if(variable.Contains("topY")){
	xmin=-3.8;
	xmax= 3.8;
	binwidth=0.01;
      }
    }
    // fill data in binned TH1F
    hist= new TH1F ( variable, variable, (int)((xmax-xmin)/binwidth), xmin, xmax);
    TH1F* ori=(TH1F*)hist->Clone("original points");
    std::cout << "fine binned theory prediction has " << hist->GetNbinsX() << " bins" << std::endl;
    std::cout << "loaded values from .dat file: " << std::endl;
    // list all data values loaded and the corresponding bin
    for(int bin=1; bin<=Nbins; ++bin){
      double x=-999;
      double y=-999;
      // NB: choose if loaded data is interpreted as points with nothing 
      //     between (like kidonakis) or as integrated over the bin range (like ahrens)
      if(points){
	// check if you are still inside the array
	//std::cout << "data point " << bin-1 << "/" << sizeof(Xvalues)/sizeof(double) << std::endl;
	if(rawHist->GetPoint(bin-1, x, y)!=-1){
	  //x=Xvalues[bin-1]; // get value from data points
	  x+=0.5*binwidth;  // add half the binwidth to get the center of the bin
	}
      }
      else{
	x=hist->GetBinCenter(bin);  // get bin center
	y=rawHist->GetY()[bin-1];
      }
      if(x!=-999){
	std::cout << "data point: " << bin;
	std::cout << "(<x>=" << x << ")-> bin";
	// get bin in target (fine binned) plot
	int bin2=bin;
	if(points) bin2=hist->FindBin(x);
	//double y=Yvalues[bin2-1];
	std::cout << bin2 << " (";
	std::cout << hist->GetBinLowEdge(bin2) << ".." << hist->GetBinLowEdge(bin2+1);
	std::cout << "): " << y << std::endl;
	// fill target (fine binned) plot
	if(!points) hist->SetBinContent(bin2, y);
	// mark bins coming from the original prediction
	ori->SetBinContent(bin2, 1.);
	// -------------------------------
	// fit range without data entries
	// -------------------------------
	// NB: needed if loaded data is interpreted as points with nothing 
	//     between (like kidonakis)
	if(points){
	  // perform a linear fit wrt previous point
	  // get the two points (this bin and the previous one)
	  int binPrev= (bin==1&&variable=="topPt") ? 0 : hist->FindBin(Xvalues[bin-2]+0.5*binwidth);
	  double x2=-1;
	  double x1= 0;
	  double y2=-1;
	  double y1= 0.;
	  rawHist->GetPoint(bin-1, x2, y2);
	  x2+=0.5*binwidth;
	  if(bin==1&&variable=="topPt"){
	    y1=0;
	    x1=0;
	  }
	  else{
	    rawHist->GetPoint(bin-2, x1, y1);
	    x1+=0.5*binwidth;
	  }
	  // calculate linear funtion
	  double a=(y2-y1)/(x2-x1);
	  double b=y1-a*x1;
	  TF1* linInterpol=new TF1("linInterpol"+getTStringFromInt(bin), "[0]*x+[1]", x1, x2);
	  linInterpol->SetParameter(0,a);
	  linInterpol->SetParameter(1,b);
	  double xlow  = (bin==1&&variable=="topPt") ? 0. : hist->GetBinLowEdge(binPrev+1);
	  double xhigh = hist->GetBinLowEdge(bin2+1);
	  std::cout << " lin. interpolation [ (" << x1 << "," << y1 << ") .. (" << x2 << "," << y2 << ") ]: " << a << "*x+" << b << std::endl;
	  linInterpol->SetRange(xlow, xhigh);
	  hist->Add(linInterpol);
	}
      }
    }
    // check theory curve
    std::cout << std::endl << "analyze theory curve:" << std::endl;
    double integralRawTheory=hist->Integral(0.,hist->GetNbinsX()+1);
    std::cout << "Integral: " << integralRawTheory << std::endl;
    if(integralRawTheory==0.){
      std::cout << "ERROR: Integral can not be 0!" << std::endl;
      exit(0);
    }
    std::cout << "binwidth: " << binwidth << std::endl;
    std::cout << "Integral*binwidth: " << integralRawTheory*binwidth << std::endl;
    std::cout << "binRange: " << xmin << ".." << xmax << std::endl;
    std::cout << "   -> reco range: " << low << ".." << high << std::endl;
    std::vector<double> recoBins_=bins_[variable];
    for(unsigned int i=0; i<recoBins_.size(); ++i){
      i==0 ? std::cout << "(" : std::cout << ", ";
      std::cout << recoBins_[i];
      if(i==recoBins_.size()-1) std::cout << ")" << std::endl;
    }
    // check if you need to divide by binwidth
    if(std::abs(1.-integralRawTheory)<0.03){
      std::cout << "Integral is approx. 1 -> need to divide by binwidth!" << std::endl;
      hist->Scale(1./binwidth);
    }
    else if(std::abs(1-integralRawTheory*binwidth)<0.03){
      std::cout << "Integral*binwidth is approx. 1 -> no scaling needed!" << std::endl;
    }
    else{
      std::cout << "need to normalize and divide by binwidth";
      hist->Scale(1./(binwidth*integralRawTheory));
    }
    // styling
    hist->GetXaxis()->SetRangeUser(low,high);
    hist->SetMarkerColor(kMagenta);
    hist->SetLineColor(  kMagenta);
    hist->SetMarkerStyle(24);
    // create canvas
    std::cout << std::endl << "create canvas " << std::endl;
    TCanvas *canv = new TCanvas(variable,variable,800,600);
    canv->cd();
    std::cout << "draw original theory curve " << std::endl;
    //temp->Draw("axis");
    hist->Draw("p");
    //hist->Draw("hist same");
    // draw original points
    if(points){
      for(int bin=1; bin<ori->GetNbinsX(); ++bin){
	// create copy of original data points with the normalized values
	if(ori->GetBinContent(bin)!=0) ori->SetBinContent(bin, hist->GetBinContent(bin));
	ori->SetMarkerColor(kBlack);
	ori->SetMarkerStyle(29);
	ori->SetMarkerSize(1);
	ori->Draw("p same");
      }
    }
    // --------------------
    // create rebinned plot
    // --------------------
    std::cout << std::endl << "create rebinned curve:" << std::endl;
    TString name="";
    // NB: add name for dataset here
    name=variable;
    if(    theory=="kidonakis") name+="approxnnlo";
    else if(theory=="ahrens"  ) name+="nlonnll"   ;
    TH1F* binnedPlot=new TH1F(name, name, bins_[variable].size()-1, &bins_[variable][0]);
    for(int bin=1; bin<=hist->GetNbinsX(); ++bin){
      double y=hist->GetBinContent(bin)*hist->GetBinWidth(bin);
      double xlow =hist->GetBinLowEdge(bin);
      double xhigh=hist->GetBinLowEdge(bin+1);
      // search corresponding bin in rebinned curve
      bool found=false;
      //std::cout << "xlow: " << xlow << ", xhigh: " << xhigh << std::endl; // FIXME
      for(int binRebinned=0; binRebinned<=binnedPlot->GetNbinsX()+1; ++binRebinned){
	if(binnedPlot->GetBinLowEdge(binRebinned)<=xlow&&binnedPlot->GetBinLowEdge(binRebinned+1)>=xhigh){
	  found=true;
	  binnedPlot->SetBinContent(binRebinned, binnedPlot->GetBinContent(binRebinned)+y);
	  break;
	}
	//else{
	//  std::cout << "not in: " << binnedPlot->GetBinLowEdge(binRebinned) << ".." << binnedPlot->GetBinLowEdge(binRebinned+1)<< std::endl;
	//}
      }
      // --------------------
      // use linear interpolation for edge bins
      // --------------------
      if(hist->GetBinCenter(bin)<high&&!found){
	std::cout << "need interpolation for bin" << bin << "(<x>=" << hist->GetBinCenter(bin) << ")!"<< std::endl;
	// search for the two bins involved
	double binLow=0;
	double binHigh=0;
	for(int binRebinned=1; binRebinned<=binnedPlot->GetNbinsX(); ++binRebinned){
	  // search for bin in binned histo where upper border of is close to lower border of unbinned histo
	  if(std::abs(binnedPlot->GetBinLowEdge(binRebinned+1)-xlow)<binwidth){
	    binLow =binRebinned; 
	    binHigh=binRebinned+1;
	    break;
	  }
	}
	std::cout << "theory bin " << xlow << ".." << xhigh << "-> reco bins ";
	std::cout << binnedPlot->GetBinLowEdge(binLow) << ".." << binnedPlot->GetBinLowEdge(binLow+1) << " & ";
	std::cout << binnedPlot->GetBinLowEdge(binHigh) << ".." << binnedPlot->GetBinLowEdge(binHigh+1) << std::endl;
	// get the two points (this bin and the previous one)
	double x2=hist->GetBinCenter (bin  );
	double x1=hist->GetBinCenter (bin-1);
	double x3=hist->GetBinCenter (bin+1);
	double y2=hist->GetBinContent(bin  );
	double y1=hist->GetBinContent(bin-1);
	double y3=hist->GetBinContent(bin+1);	
	// calculate linear funtion
	double a=(y2-y1)/(x2-x1);
	double b=y1-a*x1;
	TF1* linInterpol=new TF1("linInterpol"+getTStringFromInt(bin), "[0]*x+[1]", x1, x2);
	linInterpol->SetParameter(0,a);
	linInterpol->SetParameter(1,b);
	// calculate the corresponding area of linear function to binned curve
	double contributionLowerBin=linInterpol->Integral(xlow,binnedPlot->GetBinLowEdge(binHigh));
	double contributionUpperBin=linInterpol->Integral(binnedPlot->GetBinLowEdge(binHigh),xhigh);
	// draw interpolation function for checking
	linInterpol->SetRange(xlow,xhigh);
	linInterpol->SetLineColor(kMagenta);
	linInterpol->DrawClone("same");
	// eventually use quadratic interpolation for the first harens m(ttbar) bin
	if(theory=="ahrens"&&variable.Contains("ttbarMass")&&usequad&&x2<450){
	  // calculate quadratic funtion
	  double a2=(y2-((y3-y1))*(x2-x1)/(x3-x1))/(x2*x2-x1*x1-(x2-x1)*(x3*x3+x1*x1)/(x3-x1));
	  double b2=((y3-y1)-a2*(x3*x3-x1*x1))/(x3-x1);
	  double c2=y1-a2*x1*x1-b*x1;
	  TF1* quadInterpol=new TF1("quadInterpol"+getTStringFromInt(bin), "[0]*x*x+[1]*x+[2]", x1, x2);
	  quadInterpol->SetParameter(0,a2);
	  quadInterpol->SetParameter(1,b2);
	  quadInterpol->SetParameter(2,c2);
	  // draw quad interpolation function for checking
	  quadInterpol->SetRange(xlow,xhigh);
	  quadInterpol->SetLineColor(kGreen);
	  quadInterpol->SetLineStyle(2);
	  hist->Fit(quadInterpol, "", "same", x1, x3);
	  // calculate the corresponding area of linear function to binned curve
	  quadInterpol->DrawClone("same");
	  double areaLow =quadInterpol->Integral(xlow,binnedPlot->GetBinLowEdge(binHigh) );
	  double areaHigh=quadInterpol->Integral(binnedPlot->GetBinLowEdge(binHigh),xhigh);
	  std::cout << "ratio(high/low) linear/quadratic: " << contributionUpperBin/contributionLowerBin << "/"<< areaHigh/areaLow << std::endl;
	  contributionLowerBin=y2*binwidth*areaLow /(areaLow+areaHigh);
	  contributionUpperBin=y2*binwidth*areaHigh/(areaLow+areaHigh);
	}
	// add fitted result
	binnedPlot->SetBinContent(binLow , binnedPlot->GetBinContent(binLow )+contributionLowerBin);
	binnedPlot->SetBinContent(binHigh, binnedPlot->GetBinContent(binHigh)+contributionUpperBin);
      }
    }
    // ensure over/underflow is 0
    binnedPlot->SetBinContent(0, 0.);
    binnedPlot->SetBinContent(binnedPlot->GetNbinsX()+1, 0.);
    // ensure normalization
    binnedPlot->Scale(1./(binnedPlot->Integral(0.,binnedPlot->GetNbinsX()+1)));
    // divide by binwidth
    if(divideByBinwidth){
      for(int bin=1; bin<=binnedPlot->GetNbinsX(); ++bin){
	binnedPlot->SetBinContent(bin, binnedPlot->GetBinContent(bin)/binnedPlot->GetBinWidth(bin));
      }
    }
    std::cout << "-------------------------------------------" << std::endl;
    std::cout << "result: binned output histo" << std::endl;
    for(int bin=1; bin<=binnedPlot->GetNbinsX(); ++bin){
      std::cout << "content bin " << bin << " (" << binnedPlot->GetBinLowEdge(bin) << ".." << binnedPlot->GetBinLowEdge(bin+1) << ")= " << binnedPlot->GetBinContent(bin) << std::endl;
    }

    // styling
    binnedPlot->SetLineColor(kBlue);
    binnedPlot->SetLineWidth(2);
    std::cout << "draw rebinned theory curve " << std::endl;
    binnedPlot->Draw("hist same");
    // draw bin boundaries
    std::cout << "draw bin boundaries " << std::endl;
    int binColor=kRed;
    int binWidth=2;
    int binStyle=6;
    for(int bin=0; bin<(int)bins_.size(); ++bin){
      if(!variable.Contains("ttbarMass")||bins_[variable][bin]>=345.) drawLine(bins_[variable][bin], 0, bins_[variable][bin], hist->GetMaximum(), binColor, binWidth, binStyle);
    }
    TH1F* line=(TH1F*)hist->Clone("line");
    line->SetLineColor(binColor);
    line->SetLineWidth(binWidth);
    line->SetLineStyle(binStyle);
    // legend
    TLegend *leg = new TLegend(0.7, 0.6, 0.95, 0.9);
    legendStyle(*leg,theory);
    if(points) leg ->AddEntry(ori, "original data points","P");
    leg ->AddEntry(hist      , "theory prediction" ,"P");
    leg ->AddEntry(line      , "reco binning"      ,"L");
    leg ->AddEntry(hist      , "linear interpolation" ,"L");
    leg ->AddEntry(binnedPlot, "rebinned curve"    ,"L");
    leg->Draw("same");
    std::cout << "done" << std::endl;
    // save in png and rootfile
    std::cout << std::endl << "do saving..." << std::endl;
    canv->SaveAs(variable+"Norm_Theory.png");
    TH1F* out=(TH1F*)binnedPlot->Clone();
    out->SetTitle(variable);
    out->SetName (variable);
    out->GetXaxis()->SetTitle(xSecLabelName(variable));
    TString yTile="#frac{1}{#sigma} #frac{d#sigma}{d";
    if(variable=="ttbarMass") yTile+="m^{t#bar{t}}} [GeV^{-1}]";
    if(variable=="ttbarPt") yTile+="p_{T}^{t#bar{t}}} [GeV^{-1}]";
    if(variable=="topPt") yTile+="p_{T}^{t}} [GeV^{-1}]";
    if(variable=="topY" ) yTile+="y^{t}}";
    out->GetYaxis()->SetTitle(yTile);
    out->SetLineColor(kOrange+2);
    out->SetLineStyle(2);
    std::cout << std::endl << "draw final result " << std::endl;
    TCanvas *canv2 = new TCanvas(variable+"Rebinned",variable+"Rebinned",800,600);
    canv2->cd();
    out->Draw();
    saveToRootFile(outputRootFile, out    , true, 0,""      );
    saveToRootFile(outputRootFile, rawHist, true, 0,"graph" );
    saveToRootFile(outputRootFile, canv   , true, 0,"detail");
    std::cout << "done!" << std::endl;
  }
}
void V_t_continuous_grp7()
{
	TCanvas *c1 = new TCanvas("c1", "Vxt", 800, 600);
	TGraph *gr;
	
	//TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);

	c1->SetFillColor(42);
	c1->SetGrid();

	const Int_t n = 20;
	Double_t x[n], y[n];
	//10 for -5 to +5V, 1 to -500mV to + 500 mV, 100 to -50 mv to + 50 mV
	int scale = 1;
	char FileName[200];
	char ErrFile[200];
	char Command[300];
	
	//string err;

	// Sweep timer:
	time_t start;
	bool started;

	while(1)
	{
		//Need to be fixed to use the driver example program we adapted
	        //sprintf(Command,"./fald-acq -a 400000 -b 0 -n 1 -l 1 -g 1 -e -t 10 0100 > Data.txt");
		
		
		sprintf(FileName,"%s/Data.txt",gSystem->pwd());
		sprintf(ErrFile,"%s/Err.txt",gSystem->pwd());
		gSystem->Exec("echo 0 > /sys/devices/hw-adc-100m14b-0100/adc-100m14b-0100/enable");
		gSystem->Exec("echo 1 > /sys/devices/hw-adc-100m14b-0100/adc-100m14b-0100/enable");
		//sleep(1);
		
		//system("program args 1>/tmp/program.stdout 2>/tmp/program.stderr as in
		//http://docstore.mik.ua/orelly/perl/cookbook/ch16_08.htm
		//sprintf(Command,"%s/fald-acq -a 1000 -b 0 -n 1 -l 1 -g 1 -e -r 10 0100 1> %s 2> %s",gSystem->pwd(), FileName,ErrFile );
		//sprintf(Command,"./fald-acq -a 100 -b 0 -n 1 -l 1 -g 1 -c 1 -t 10000 -r 10 0100 > %s",FileName);
	    	//sprintf(Command,"%s/fald-acq -a 1000 -b 0 -n 1 -l 1 -g 1 -e -r 10 0100",gSystem->pwd());
		//gSystem->Exec(Command);
		
		sprintf(Command,"%s/fald-acq -a 500 -b 0 -n 1 -l 1 -g 1 -e -r 1 0100 1> %s 2> %s",gSystem->pwd(), FileName,ErrFile );
		FILE *test = gSystem->OpenPipe(Command,"r");
		gSystem->ClosePipe(test);
		
		//gr = new TGraph("/tmp/fmcadc.0x0100.ch1.dat", "%lg %lg %*lg %*lg %*lg");

		
		
		
		//gSystem->Sleep(100);
		
		
		
		//if (TFile::SizeOf(FileName)<=0) break;
		//cin >> err;
		//cout << err << endl;
		//strcmp(err,"./fald-acq: cannot start acquisition: Input/output error");
		//cout <<"running" <<endl;
		//cout << "TGraph *G1 = new TGraph(FileName = " << FileName << ") , loop i = " << i << endl;
		//See the columns configuration in FileName
		
	
		gr = new TGraph("/tmp/fmcadc.0x0100.ch1.dat", "%lg %lg");
		//c1->cd();

		// Get very first point of graph:
		#define THRESHOLD 0.1
		Double_t sample, value1, value2;
		gr->GetPoint(0,sample,value1);
		gr->GetPoint(3,sample,value2);
		if(value1 < 0 && value2 > 0) {
		  std::cout << "Triggered!" << std::endl;
		  if(!started) {
		    // FIXME: use nicer timing function!
		    start = time(NULL);
		    started = true;
		  }
		  else {
		    double diff = time(NULL) - start;
		    started = false;
		    std::cout << "dT: " << diff << " / " << (1/diff) << "Hz" << std::endl;
		  }
		}
		
		gSystem->ProcessEvents();
		//TGraph *G2 = new TGraph();
		
		//cout <<"2" <<endl;
		
		gr->SetLineColor(2);
		gr->SetLineWidth(4);
		gr->SetMarkerColor(4);
		gr->SetMarkerStyle(21);
		//cout <<"a simple graph" <<endl;
		gr->SetTitle("Vxt");
		gr->GetXaxis()->SetTitle("time sample");
		gr->GetYaxis()->SetTitle("Volts");
		//cout <<"3" <<endl;
		
		gr->Draw("ACP");

		gSystem->ProcessEvents();
		//cout << "Draw" << endl;
		//cout <<"4" <<endl;
		// TCanvas::Update() draws the frame, after which one can change it
		c1->Update();
		c1->GetFrame()->SetFillColor(21);
		c1->GetFrame()->SetBorderSize(12);
		c1->Modified();
		//cout <<"5" <<endl;
		
		gSystem->ProcessEvents();
		
		
		
	}
	 //gr = new TGraph(n,x,y);
	  delete gr;
	   cout << "Bye" << endl;
	 delete c1;
	 //
	return;
}
Example #20
0
bool check(int n = 2) {
   TFile *file = TFile::Open(TString::Format("merged%d.root",n));

   bool result = true;
   TH1F *h; file->GetObject("h1",h);
   if (!h) {
      Error("execFileMerger","h1 is missing\n");
      result = false;
   }
   if (h->GetBinContent(2) != n || h->GetBinContent(3) != n) {
      Error("execFileMerger","h1 not added properly");
      result = false;
   }
   
   THnSparseF *sparse; file->GetObject("sparse",sparse);
   if (!sparse) {
      Error("execFileMerger","sparse is missing\n");
      result = false;
   } else {
      Int_t coordIdx[5] = {1, 2, 3, 4, 5};
      Double_t cont = sparse->GetBinContent(coordIdx);
      if (cont > n + 0.4 || cont < n - 0.4) {
         Error("execFileMerger","sparse merge failed: expected bin content %g, read %g\n",
               (Double_t)n, cont);
         result = false;
      }
      Double_t entries = sparse->GetEntries();
      if (entries > n + 0.4 || entries < n - 0.4) {
         Error("execFileMerger","sparse merge failed: expected %g entries, read %g\n",
               (Double_t)n, entries);
         result = false;
      }
   }
   
   THStack *stack; file->GetObject("stack",stack);
   if (!stack) {
      Error("execFileMerger","stack is missing\n");
      result = false;
   }
   h = (TH1F*)stack->GetHists()->FindObject("hs_1");
   if (!h) {
      Error("execFileMerger","hs_1 is missing\n");
      result = false;
   }
   if (h->GetBinContent(2) != n || h->GetBinContent(3) != n) {
      Error("execFileMerger","hs_1 not added properly");
      result = false;
   }
   h = (TH1F*)stack->GetHists()->FindObject("hs_2");
   if (!h) {
      Error("execFileMerger","hs_2 is missing\n");
      result = false;
   }
   if (h->GetBinContent(4) != n || h->GetBinContent(5) != n) {
      Error("execFileMerger","hs_2 not added properly");
      result = false;
   }

   TGraph *gr; file->GetObject("exgraph",gr);
   if (!gr) {
      Error("execFileMerger","exgraph is missing\n");
      result = false;
   }
   if (gr->GetN() != ( n * 3)) {
      Error("execFileMerger","exgraph not added properly n=%d rather than %d",gr->GetN(),n*3);
      result = false;            
   } else {
      for(Int_t k = 0; k < gr->GetN(); ++k) {
         double x,y;
         gr->GetPoint(k,x,y);
         if ( x != ( (k%3)+1 ) ||  y != ( (k%3)+1 ) ) {
            Error("execFileMerger","exgraph not added properly");
            result = false;            
         }
      }
   }
   
   TTree *tree; file->GetObject("tree",tree);
   if (!tree) {
      Error("execFileMerger","tree is missing\n");
      result = false;
   }
   if (tree->GetEntries() != n*2) {
      Error("execFileMerger","tree does not have the expected number of entries: %lld rather than %d",tree->GetEntries(),n*2);
      result = false;            
   } else {
      if ( tree->GetEntries("data==1") != n ) {
         Error("execFileMerger","tree does not have the expected data. We got %lld entries with 'data==1' rather than %d",tree->GetEntries("data==1"),n);
         tree->Scan();
         result = false;
      }
   }   
   return result;
}
Example #21
0
void get_results(){
  
  gROOT->SetStyle("Plain");
  
  printf("\n");
  printf(" ---------------------------------------------------------------------------\n");
  printf("                Sensitivity vs. nSig and Sigma in Fit\n");
  printf(" ---------------------------------------------------------------------------\n");
  printf(" nSig / SigFit--> |    0.1   |   0.2   |   0.3   |   0.4   |  W. Avg  (val) \n");
  printf(" ---------------------------------------------------------------------------\n");

  
  Double_t p1x, p1y;
  Double_t p2x, p2y;
  Double_t ix, iy;
  
  TObjArray *a1 = new TObjArray(0);
  
  TGraph *graph0130 = new TGraph(5);
  graph0130->SetTitle("Sensitivity vs. Sig-fit");
  graph0130->SetName("graph0130");
  
  TGraph *graph1 = new TGraph(5);
  graph1->SetTitle("Sensitivity vs. Sig-fit");
  graph1->SetName("graph1");
  
  TGraph *graph0196 = new TGraph(5);
  graph0196->SetTitle("Sensitivity vs. Sig-fit");
  graph0196->SetName("graph0196");
  
  TCanvas *can1 = new TCanvas("can1", "varfits1", 1500, 900);
  can1->Divide(5,3);
  
  /***************************************************************************
     nSig = 0.130							      
   ****************************************************************************/
  
  // =================== nsig=0.130, tSig=0.1 Sig-fit=0.1 ==================
  can1->cd(1);
  gPad->SetGrid();
  
  TFile lhns("varsig0130_1.root");
  TGraph *gs130_1 = (TGraph*)lhns.Get("DilErrvsdm");
  gs130_1->SetTitle("nSig=0.130, tSig=0.1, Sig-fit=0.1");
  gs130_1->SetName("gs130_1");
  gs130_1->GetXaxis()->SetTitle("dm");
  gs130_1->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs130_1->Draw("AP*");
  
  gs130_1->GetPoint(16, p1x, p1y);
  gs130_1->GetPoint(17, p2x, p2y);
  
  Double_t vs130_1 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);
  
  graph0130->SetPoint(0,0.1,vs130_1);
  
  a1.Add(gs130_1);
  
  // =================== nsig=0.130, tSig=0.1 Sig-fit=0.2 ==================
  can1->cd(2);
  gPad->SetGrid();
  
  TFile lhns("varsig0130_2.root");
  TGraph *gs130_2 = (TGraph*)lhns.Get("DilErrvsdm");
  gs130_2->SetTitle("nSig=0.130, tSig=0.1, Sig-fit=0.2");
  gs130_2->SetName("gs130_2");
  gs130_2->GetXaxis()->SetTitle("dm");
  gs130_2->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs130_2->Draw("AP*");
  
  gs130_2->GetPoint(14, p1x, p1y);
  gs130_2->GetPoint(15, p2x, p2y);
  
  Double_t vs130_2 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);
  
  graph0130->SetPoint(1,0.2,vs130_2);
  
  a1.Add(gs130_2);
  
  // =================== nsig=0.130, tSig=0.1 Sig-fit=0.3 ====================
  can1->cd(3);
  gPad->SetGrid();
  
  TFile lhns("varsig0130_3.root");
  TGraph *gs130_3 = (TGraph*)lhns.Get("DilErrvsdm");
  gs130_3->SetTitle("nSig=0.130, tSig=0.1, Sig-fit=0.3");
  gs130_3->SetName("gs130_3");
  gs130_3->GetXaxis()->SetTitle("dm");
  gs130_3->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs130_3->Draw("AP*");
  
  gs130_3->GetPoint(10, p1x, p1y);
  gs130_3->GetPoint(11, p2x, p2y);
  
  Double_t vs130_3 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);
  
  graph0130->SetPoint(2,0.3,vs130_3);
  
  a1.Add(gs130_3);
  
  // =================== nsig=0.130, tSig=0.1 Sig-fit=0.4 ====================
  can1->cd(4);
  gPad->SetGrid();
  
  TFile lhns("varsig0130_4.root");
  TGraph *gs130_4 = (TGraph*)lhns.Get("DilErrvsdm");
  gs130_4->SetTitle("nSig=0.130, tSig=0.1, Sig-fit=0.4");
  gs130_4->SetName("gs130_4");
  gs130_4->GetXaxis()->SetTitle("dm");
  gs130_4->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs130_4->Draw("AP*");
  
  gs130_4->GetPoint(13, p1x, p1y);
  gs130_4->GetPoint(14, p2x, p2y);
  
  Double_t vs130_4 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);
  
  graph0130->SetPoint(3,0.4,vs130_4);
  
  a1.Add(gs130_4);
  
  // =================== nsig=0.130, tSig=0.1 Sig-fit=Avg =====================
  can1->cd(5);
  gPad->SetGrid();
  
  TFile lhns("varsig0130_a.root");
  TGraph *gs130_a = (TGraph*)lhns.Get("DilErrvsdm");
  gs130_a->SetTitle("nSig=0.130, tSig=0.1, Sig-fit=Avg");
  gs130_a->SetName("gs130_a");
  gs130_a->GetXaxis()->SetTitle("dm");
  gs130_a->GetYaxis()->SetTitle("95% CL");

  TGraph *gs130_sf = (TGraph*)lhns.Get("SigFit");
  gs130_sf->SetTitle("Sigma_Avg in Fit vs. dm , nSig=0.130");
  gs130_sf->SetName("gs130_sf");
  gs130_sf->GetXaxis()->SetTitle("dm");
  gs130_sf->GetYaxis()->SetTitle("Sigma in Fit");
  
  lhns.Close();
  
  gs130_a->Draw("AP*");
  
  gs130_a->GetPoint(12, p1x, p1y);
  gs130_a->GetPoint(13, p2x, p2y);
  
  Double_t vs130_a = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph0130->SetPoint(4,0.270111,vs130_a);

  a1.Add(gs130_a);
  a1.Add(gs130_sf);

  printf("       0.130      |  %5.3f  |  %5.3f  |  %5.3f  |  %5.3f  |  %5.3f (0.270) \n",vs130_1,vs130_2,vs130_3,vs130_4,vs130_a);

   //----------- plot the sig-fit vs. dm; histogram sig-fit  ----- 
  TCanvas *c0130sf = new TCanvas("Sigfit_vs_dm_0130", "graph0130sf", 800, 400);
  c0130sf->Divide(2,1);
  c0130sf->cd(1);
  gPad->SetGrid();
  gs130_sf->Draw("AP*");
  
  c0130sf->cd(2);
  TH1F *hs0130_sf = new TH1F("hs0130_sf", "SigFit spread, nSig=0.130", 10, 0.26, 0.28);
  for (Int_t i=0.; i<20.; i++){
    gs130_sf->GetPoint(i,ix,iy);
    //cout << i << ", "<< ix << ", "<< iy <<endl;
    hs0130_sf->Fill(iy);
  }
  gPad->SetGrid();
  hs0130_sf->Draw();

  a1.Add(hs0130_sf);
  a1.Add(c0130sf);
  //--------------- plot the sensitivity vs sig-fit -----------
  TCanvas *c0130 = new TCanvas("Sens_vs_sigfit_0130", "graph0130", 400, 400);
  c0130->SetGrid();
  graph0130->GetXaxis()->SetTitle("Sigma in fit");
  graph0130->GetYaxis()->SetTitle("Sensitivity");
  graph0130->Draw("AP*");

  a1.Add(graph0130);
  a1.Add(c0130);

 
  /***************************************************************************
	nSig = 0.163								      
   **************************************************************************/

  //  ================== nsig=0.163, tSig=0.1 Sig-fit=0.1 ==================
  can1->cd(6);
  gPad->SetGrid();
  
  TFile lhns("varsigma_1.root");
  TGraph *gs1 = (TGraph*)lhns.Get("DilErrvsdm");
  gs1->SetTitle("nSig=0.163, tSig=0.1, Sig-fit=0.1");
  gs1->SetName("gs1");
  gs1->GetXaxis()->SetTitle("dm");
  gs1->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs1->Draw("AP*");
 
  gs1->GetPoint(16, p1x, p1y);
  gs1->GetPoint(17, p2x, p2y);

  Double_t vs1 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph1->SetPoint(0,0.1,vs1);
 
  a1.Add(gs1);
 
  //  ================== nsig=0.163, tSig=0.1 Sig-fit=0.2 ==================
  can1->cd(7);
  gPad->SetGrid();
  
  TFile lhns("varsigma_2.root");
  TGraph *gs2 = (TGraph*)lhns.Get("DilErrvsdm");
  gs2->SetTitle("nSig=0.163, tSig=0.1, Sig-fit=0.2");
  gs2->SetName("gs2");
  gs2->GetXaxis()->SetTitle("dm");
  gs2->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs2->Draw("AP*");
 
  gs2->GetPoint(14, p1x, p1y);
  gs2->GetPoint(15, p2x, p2y);

  Double_t vs2 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph1->SetPoint(1,0.2,vs2);

  a1.Add(gs2);
 
  //  ================== nsig=0.163, tSig=0.1 Sig-fit=0.3 ==================
  can1->cd(8);
  gPad->SetGrid();
  
  TFile lhns("varsigma_3.root");
  TGraph *gs3 = (TGraph*)lhns.Get("DilErrvsdm");
  gs3->SetTitle("nSig=0.163, tSig=0.1, Sig-fit=0.3");
  gs3->SetName("gs3");
  gs3->GetXaxis()->SetTitle("dm");
  gs3->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs3->Draw("AP*");
 
  gs3->GetPoint(10, p1x, p1y);
  gs3->GetPoint(11, p2x, p2y);

  Double_t vs3 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph1->SetPoint(2,0.3,vs3);
  
   a1.Add(gs3);

  // ================== nsig=0.163, tSig=0.1 Sig-fit=0.4 ==================
  can1->cd(9);
  gPad->SetGrid();
  
  TFile lhns("varsigma_4.root");
  TGraph *gs4 = (TGraph*)lhns.Get("DilErrvsdm");
  gs4->SetTitle("nSig=0.163, tSig=0.1, Sig-fit=0.4");
  gs4->SetName("gs4");
  gs4->GetXaxis()->SetTitle("dm");
  gs4->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs4->Draw("AP*");
 
  gs4->GetPoint(13, p1x, p1y);
  gs4->GetPoint(14, p2x, p2y);

  Double_t vs4 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph1->SetPoint(3,0.4,vs4);
  
  a1.Add(gs4);

  // ================== nsig=0.163, tSig=0.1 Sig-fit=Avg ==================
  can1->cd(10);
  gPad->SetGrid();
  
  TFile lhns("varsigma_a.root");
  TGraph *gsa = (TGraph*)lhns.Get("DilErrvsdm");
  gsa->SetTitle("nSig=0.163, tSig=0.1, Sig-fit=Avg");
  gsa->SetName("gsa");
  gsa->GetXaxis()->SetTitle("dm");
  gsa->GetYaxis()->SetTitle("95% CL");

  TGraph *gs_sf = (TGraph*)lhns.Get("SigFit");
  gs_sf->SetTitle("Sigma_Avg in Fit vs. dm , nSig=0.163");
  gs_sf->SetName("gs_sf");
  gs_sf->GetXaxis()->SetTitle("dm");
  gs_sf->GetYaxis()->SetTitle("Sigma in Fit");

  lhns.Close();
  
  gsa->Draw("AP*");
 
  gsa->GetPoint(11, p1x, p1y);
  gsa->GetPoint(12, p2x, p2y);

  Double_t vsa = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph1->SetPoint(4,0.313349,vsa);
 
   a1.Add(gsa);
   a1.Add(gs_sf);

  printf("       0.163      |  %5.3f  |  %5.3f  |  %5.3f  |  %5.3f  |  %5.3f (0.313) \n",vs1,vs2,vs3,vs4,vsa);

   //----------- plot the sig-fit vs. dm; histogram sig-fit  ----- 
  TCanvas *csf = new TCanvas("Sigfit_vs_dm_0163", "graphsf", 800, 400);
  csf->Divide(2,1);
  csf->cd(1);
  gPad->SetGrid();
  gs_sf->Draw("AP*");
  
  csf->cd(2);
  TH1F *hs_sf = new TH1F("hs_sf", "SigFit spread, nSig=0.163", 10, 0.3, 0.325);
  for (Int_t i=0.; i<20.; i++){
    gs_sf->GetPoint(i,ix,iy);
    //cout << i << ", "<< ix << ", "<< iy <<endl;
    hs_sf->Fill(iy);
  }
  gPad->SetGrid();
  hs_sf->Draw();

  a1.Add(hs_sf);
  a1.Add(csf);

  //--------------- plot the sensitivity vs sig-fit -----------
  TCanvas *can2 = new TCanvas("Sens_vs_sigfit_0163", "graph1", 400, 400);
  can2->SetGrid();
  graph1->GetXaxis()->SetTitle("Sigma in fit");
  graph1->GetYaxis()->SetTitle("Sensitivity");
  graph1->Draw("AP*");

   a1.Add(graph1);
   a1.Add(can2);

  /***************************************************************************
	nSig = 0.196								      
   **************************************************************************/

  //  ================== nsig=0.196, tSig=0.1 Sig-fit=0.1 ==================
  can1->cd(11);
  gPad->SetGrid();
  
  TFile lhns("varsig0196_1.root");
  TGraph *gs196_1 = (TGraph*)lhns.Get("DilErrvsdm");
  gs196_1->SetTitle("nSig=0.196, tSig=0.1, Sig-fit=0.1");
  gs196_1->SetName("gs196_1");
  gs196_1->GetXaxis()->SetTitle("dm");
  gs196_1->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs196_1->Draw("AP*");
 
  gs196_1->GetPoint(16, p1x, p1y);
  gs196_1->GetPoint(17, p2x, p2y);

  Double_t vs196_1 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph0196->SetPoint(0,0.1,vs196_1);

  a1.Add(gs196_1);

  // ================== nsig=0.196, tSig=0.1 Sig-fit=0.2 ====================
  can1->cd(12);
  gPad->SetGrid();
  
  TFile lhns("varsig0196_2.root");
  TGraph *gs196_2 = (TGraph*)lhns.Get("DilErrvsdm");
  gs196_2->SetTitle("nSig=0.196, tSig=0.1, Sig-fit=0.2");
  gs196_2->SetName("gs196_2");
  gs196_2->GetXaxis()->SetTitle("dm");
  gs196_2->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs196_2->Draw("AP*");
 
  gs196_2->GetPoint(14, p1x, p1y);
  gs196_2->GetPoint(15, p2x, p2y);

  Double_t vs196_2 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph0196->SetPoint(1,0.2,vs196_2);

  a1.Add(gs196_2);

  // ================== nsig=0.196, tSig=0.1 Sig-fit=0.3 ==================
  can1->cd(13);
  gPad->SetGrid();
  
  TFile lhns("varsig0196_3.root");
  TGraph *gs196_3 = (TGraph*)lhns.Get("DilErrvsdm");
  gs196_3->SetTitle("nSig=0.196, tSig=0.1, Sig-fit=0.3");
  gs196_3->SetName("gs196_3");
  gs196_3->GetXaxis()->SetTitle("dm");
  gs196_3->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs196_3->Draw("AP*");
 
  gs196_3->GetPoint(10, p1x, p1y);
  gs196_3->GetPoint(11, p2x, p2y);

  Double_t vs196_3 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph0196->SetPoint(2,0.3,vs196_3);

  a1.Add(gs196_3);

  // ================== nsig=0.196, tSig=0.1 Sig-fit=0.4 ==================
  can1->cd(14);
  gPad->SetGrid();
  
  TFile lhns("varsig0196_4.root");
  TGraph *gs196_4 = (TGraph*)lhns.Get("DilErrvsdm");
  gs196_4->SetTitle("nSig=0.196, tSig=0.1, Sig-fit=0.4");
  gs196_4->SetName("gs196_4");
  gs196_4->GetXaxis()->SetTitle("dm");
  gs196_4->GetYaxis()->SetTitle("95% CL");
  lhns.Close();
  
  gs196_4->Draw("AP*");
 
  gs196_4->GetPoint(13, p1x, p1y);
  gs196_4->GetPoint(14, p2x, p2y);

  Double_t vs196_4 = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph0196->SetPoint(3,0.4,vs196_4);

  a1.Add(gs196_4);

  // ================== nsig=0.196, tSig=0.1 Sig-fit=Avg ==================
  can1->cd(15);
  gPad->SetGrid();
  
  TFile lhns("varsig0196_a.root");
  TGraph *gs196_a = (TGraph*)lhns.Get("DilErrvsdm");
  gs196_a->SetTitle("nSig=0.196, tSig=0.1, Sig-fit=Avg");
  gs196_a->SetName("gs196_a");
  gs196_a->GetXaxis()->SetTitle("dm");
  gs196_a->GetYaxis()->SetTitle("95% CL");

  TGraph *gs196_sf = (TGraph*)lhns.Get("SigFit");
  gs196_sf->SetTitle("Sigma(Avg) in Fit vs. dm (nSig=0.196)");
  gs196_sf->SetName("gs196_sf");
  gs196_sf->GetXaxis()->SetTitle("dm");
  gs196_sf->GetYaxis()->SetTitle("Sigma in Fit");
  lhns.Close();
  
  gs196_a->Draw("AP*");
 
  gs196_a->GetPoint(10, p1x, p1y);
  gs196_a->GetPoint(11, p2x, p2y);

  Double_t vs196_a = (((1-p1y)/(1-p2y))*p2x - p1x)/(((1-p1y)/(1-p2y))-1);

  graph0196->SetPoint(4,0.356301,vs196_a);

  a1.Add(gs196_a);
  a1.Add(gs196_sf);

  printf("       0.196      |  %5.3f  |  %5.3f  |  %5.3f  |  %5.3f  |  %5.3f (0.270) \n",vs196_1,vs196_2,vs196_3,vs196_4,vs196_a);

   //----------- plot the sig-fit vs. dm; histogram sig-fit  ----- 
  TCanvas *c0196sf = new TCanvas("Sigfit_vs_dm_0196", "graph0196sf", 800, 400);
  c0196sf->Divide(2,1);
  c0196sf->cd(1);
  gPad->SetGrid();
  gs196_sf->Draw("AP*");
  
  c0196sf->cd(2);
  TH1F *hs0196_sf = new TH1F("hs0196_sf", "SigFit spread, nSig=0.196", 10, 0.34, 0.37);
  for (Int_t i=0.; i<20.; i++){
    gs196_sf->GetPoint(i,ix,iy);
    //cout << i << ", "<< ix << ", "<< iy <<endl;
    hs0196_sf->Fill(iy);
  }
  gPad->SetGrid();
  hs0196_sf->Draw();

  a1.Add(hs0196_sf);
  a1.Add(c0196sf);

  //--------------- plot the sensitivity vs sig-fit -----------
  TCanvas *c0196 = new TCanvas("Sens_vs_sigfit_0196", "graph0196", 400, 400);
  c0196->SetGrid();
  graph0196->GetXaxis()->SetTitle("Sigma in fit");
  graph0196->GetYaxis()->SetTitle("Sensitivity");
  graph0196->Draw("AP*");

  a1.Add(graph0196);
  a1.Add(c0196);

  a1.Add(can1);
  //can1->Close();

  /***************************************************************************
   **************************************************************************/

  printf(" ---------------------------------------------------------------------------\n");
  printf("\n");

  TCanvas *combined = new TCanvas("Sens_vs_dm_combined", "combined", 400, 400);
  combined->SetGrid();
  graph0130->SetMarkerColor(4);
  graph0130->SetMarkerStyle(4);
  graph0130->Draw("AP");
  graph1->SetMarkerColor(2);
  graph1->SetMarkerStyle(22);
  graph1->Draw("P");
  graph0196->SetMarkerColor(8);
  graph0196->SetMarkerStyle(28);
  graph0196->Draw("P");

  a1.Add(combined);

  TFile file1("get_results.root", "recreate");
  a1.Write();
  file1.Close();

  }
Example #22
0
void Polarization(){

    TGraph *gObs;
    TGraph *gExp;
    TGraph *gObsL;
    TGraph *gExpL;
    TGraph *gObsR;
    TGraph *gExpR;
    
    TFile *fc = TFile::Open("Limits2DHistograms_T2tt_postfit.root");
    TFile *fl = TFile::Open("Limits2DHistograms_T2tt_lefthanded_postfit.root");
    TFile *fr = TFile::Open("Limits2DHistograms_T2tt_righthanded_postfit.root");
    
    TGraph *g;
    fc->cd();
    g = (TGraph*)fc->Get("gObs");
    gObs = (TGraph*)g->Clone("Obs");
    g = (TGraph*)fc->Get("gExp");
    gExp = (TGraph*)g->Clone("Exp");
    fl->cd();
    g = (TGraph*)fl->Get("gObs_2");
    gObsL = (TGraph*)g->Clone("ObsL");
    g = (TGraph*)fl->Get("gExp_2");
    gExpL = (TGraph*)g->Clone("ExpL");
    fr->cd();
    g = (TGraph*)fr->Get("gObs");
    gObsR = (TGraph*)g->Clone("ObsR");
    g = (TGraph*)fr->Get("gExp");
    gExpR = (TGraph*)g->Clone("ExpR");
    
    gObs->SetLineWidth(4);
    gExp->SetLineWidth(4);
    gObsL->SetLineWidth(2);
    gExpL->SetLineWidth(2);
    gObsR->SetLineWidth(2);
    gExpR->SetLineWidth(2);
    gObs->SetLineStyle(1);
    gExp->SetLineStyle(7);
    gObsL->SetLineStyle(1);
    gExpL->SetLineStyle(7);
    gObsR->SetLineStyle(1);
    gExpR->SetLineStyle(7);
    gObs->SetLineColor(kBlack);
    gExp->SetLineColor(kBlack);
    gObsL->SetLineColor(kBlue);
    gExpL->SetLineColor(kBlue);
    gObsR->SetLineColor(kRed);
    gExpR->SetLineColor(kRed);
    if(killlowdiag){
    for( int i = gObs->GetN()-1; i>=0;--i){
        double x,y;
        gObs->GetPoint(i,x,y);
        if(x-y<172.5) gObs->RemovePoint(i);
    }
    for( int i = gExp->GetN()-1; i>=0;--i){
        double x,y;
        gExp->GetPoint(i,x,y);
        if(x-y<172.5) gExp->RemovePoint(i);
    }
    }
    for( int i = gObsL->GetN()-1; i>=0;--i){
        double x,y;
        gObsL->GetPoint(i,x,y);
        if(x-y<172.5) gObsL->RemovePoint(i);
    }
    for( int i = gObsR->GetN()-1; i>=0;--i){
        double x,y;
        gObsR->GetPoint(i,x,y);
        if(x-y<172.5) gObsR->RemovePoint(i);
    }
    for( int i = gExpL->GetN()-1; i>=0;--i){
        double x,y;
        gExpL->GetPoint(i,x,y);
        if(x-y<172.5) gExpL->RemovePoint(i);
    }
    for( int i = gExpR->GetN()-1; i>=0;--i){
        double x,y;
        gExpR->GetPoint(i,x,y);
        if(x-y<172.5) gExpR->RemovePoint(i);
    }

    
   TCanvas *c1 = new TCanvas("c1", "c1",50,50,600,600);
   gStyle->SetOptFit(1);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   gStyle->SetErrorX(0.5); 
   //c1->Range(-6.311689,-1.891383,28.75325,4.56342);
   c1->SetFillColor(0);
   c1->SetBorderMode(0);
   c1->SetBorderSize(2);
   //c1->SetLogy();
   c1->SetTickx(1);
   c1->SetTicky(1);
   c1->SetLeftMargin(0.15);
   c1->SetRightMargin(0.05);
   c1->SetTopMargin(0.07);
   c1->SetBottomMargin(0.15);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   c1->SetFrameFillStyle(0);
   c1->SetFrameBorderMode(0);
   gStyle->SetHatchesLineWidth(0);

   TH1F *hSum = new TH1F("hSum","",10,150,950);
   hSum->SetMinimum(0.);
   hSum->SetMaximum(550);
   hSum->SetDirectory(0);
   hSum->SetStats(0);
    hSum->Draw();
    hSum->GetYaxis()->SetRangeUser(0,500);
    hSum->GetXaxis()->SetRangeUser(150,950);

   Int_t ci;   // for color index setting
   ci = TColor::GetColor("#000099");
   hSum->SetLineColor(ci);
   hSum->SetLineStyle(0);
   hSum->SetMarkerStyle(20);
   hSum->GetXaxis()->SetTitle("m_{#tilde{t}} [GeV]");
   //hSum->GetXaxis()->SetBit(TAxis::kLabelsVert);
   hSum->GetXaxis()->SetLabelFont(42);
   //hSum->GetXaxis()->SetLabelOffset(0.005);
   hSum->GetXaxis()->SetLabelSize(0.035);
   hSum->GetXaxis()->SetTitleSize(0.06);
   hSum->GetXaxis()->SetTitleOffset(1.2);
   hSum->GetXaxis()->SetTitleFont(42);
   hSum->GetYaxis()->SetTitle("m_{#tilde{#chi}}_{1}^{0} [GeV]");
   hSum->GetYaxis()->SetLabelFont(42);
   //hSum->GetYaxis()->SetLabelOffset(0.007);
   hSum->GetYaxis()->SetLabelSize(0.035);
   hSum->GetYaxis()->SetTitleSize(0.05);
   hSum->GetYaxis()->SetTitleOffset(1.3);
   hSum->GetYaxis()->SetTitleFont(42);
    
    //TLegend *leg = new TLegend(0.4992416,0.4811189,0.898906,0.7503497,NULL,"brNDC");
    //TLegend *leg = new TLegend(0.4992416,0.4811189,0.698906,0.7503497,NULL,"brNDC");
    //TLegend *leg = new TLegend(0.6992416,0.2811189,0.898906,0.4503497,NULL,"brNDC");
    //TLegend *leg = new TLegend(0.6992416,0.3311189,0.898906,0.7903497,NULL,"brNDC");
    //TLegend *leg = new TLegend(0.7582416,0.4211189,0.912,0.8043497,NULL,"brNDC");
    TLegend *legE = new TLegend(0.51,0.675,0.81,0.855,NULL,"brNDC");
    //leg-> SetNColumns(2);
    legE->SetBorderSize(0);
    legE->SetTextSize(0.04);
    legE->SetTextFont(42);
    legE->SetLineColor(1);
    legE->SetLineStyle(1);
    legE->SetLineWidth(2);
    legE->SetFillColor(0);
    legE->SetFillStyle(1001);
    legE->SetHeader("Expected");
    legE->AddEntry(gExp, "unpolarized","l");
    legE->AddEntry(gExpR, "right-handed","l");
    legE->AddEntry(gExpL, "left-handed","l");
    
    TLegend *legO = new TLegend(0.175,0.675,0.50,0.855,NULL,"brNDC");
    //legO-> SetNColumns(2);
    legO->SetBorderSize(0);
    legO->SetTextSize(0.04);
    legO->SetTextFont(42);
    legO->SetLineColor(1);
    legO->SetLineStyle(1);
    legO->SetLineWidth(2);
    legO->SetFillColor(0);
    legO->SetFillStyle(1001);
    legO->SetHeader("Observed");
    legO->AddEntry(gObs, "unpolarized","l");
    legO->AddEntry(gObsR, "right-handed","l");
    legO->AddEntry(gObsL, "left-handed","l");
    
    
    TGraph* graphWhite = new TGraph(5);
    graphWhite->SetName("white");
    graphWhite->SetTitle("white");
    graphWhite->SetFillColor(kWhite);
    graphWhite->SetFillStyle(1001);
    graphWhite->SetLineColor(kBlack);
    graphWhite->SetLineStyle(1);
    graphWhite->SetLineWidth(3);
    graphWhite->SetPoint(0,150, 500);
    graphWhite->SetPoint(1,950, 500);
    graphWhite->SetPoint(2,950, 500*0.6666666667);
    graphWhite->SetPoint(3,150, 500*0.6666666667);
    graphWhite->SetPoint(4,150, 500);
    
    Float_t diagX[4] = {175.+25.,175.+25.+5000,175.-25.+5000,175.-25.};
    Float_t diagY[4] = {0,5000,5000,0};
    TGraph *gdiagonal = new TGraph(4, diagX, diagY);
    gdiagonal->SetName("MtopDiagonal");
    gdiagonal->SetFillColor(kWhite);
    //#gdiagonal->SetFillColor(18);
    TLine* ldiagonal = new TLine(175,0.,650-25.,450);
    //TLine* ldiagonal = new TLine(175.,25,175+500,500);
    ldiagonal->SetLineColor(kGray);
    ldiagonal->SetLineStyle(2);
    TLatex* tdiagonal = new TLatex(400-2.5, 400-172.5,"m_{#tilde{t}} = m_{t} + m_{#tilde{#chi}_{1}^{0}}");
    //tdiagonal->SetTextAngle(TMath::RadToDeg()*TMath::ATan(float(800)/float(500)));
    tdiagonal->SetTextAngle(56.31);
    tdiagonal->SetTextColor(kGray+2);
    tdiagonal->SetTextAlign(11);
    tdiagonal->SetTextSize(0.025);

    TLine* l2 = new TLine(150,75,585,500);
    l2->SetLineColor(kGray);
    l2->SetLineStyle(2);
    if(killlowdiag){
        l2->SetX1(200); l2->SetY1(0); l2->SetX2(600); l2->SetY2(400);
    }
    TLatex *t2 = new TLatex(300, 300-72.5,"m_{#tilde{t}} = m_{W} + m_{#tilde{#chi}_{1}^{0}}");
    //t2->SetTextAngle(TMath::RadToDeg()*TMath::ATan(float(800)/float(500)));
    t2->SetTextAngle(56.31);
    t2->SetTextColor(kGray+2);
    t2->SetTextAlign(11);
    t2->SetTextSize(0.025);

    hSum->Draw("axis");
    
    gExpR->Draw("c");
    gExpL->Draw("c");
    gExp->Draw("c");
    gObsR->Draw("c");
    gObsL->Draw("c");
    gObs->Draw("c");

    gdiagonal->Draw("FSAME");
    ldiagonal->Draw("LSAME");
    l2->Draw();
    if(!killlowdiag) t2->Draw();
    tdiagonal->Draw("SAME");
    graphWhite->Draw("FSAME");
    graphWhite->Draw("LSAME");

    legE->Draw();
    legO->Draw();
    
    TLatex* textModelLabel= new TLatex(0.175,0.92,"pp #rightarrow #tilde{t} #tilde{t}*, #tilde{t} #rightarrow t #tilde{#chi}^{0}_{1}  NLO+NLL exclusion");
    //TLatex* textModelLabel= new TLatex(0.175,0.92,"pp #rightarrow #tilde{t} #tilde{t}*, #tilde{t} #rightarrow t #tilde{#chi}^{0}_{1}");
    //TLatex* textModelLabel= new TLatex(0.175,0.92,"#tilde{#chi} ");
    textModelLabel->SetNDC();
    textModelLabel->SetTextAlign(13);
    textModelLabel->SetTextFont(42);
    textModelLabel->SetTextSize(0.042);
    textModelLabel->Draw();
    
    //final CMS style
    TLatex *tLumi = new TLatex(0.95,0.944,"2.3 fb^{-1} (13 TeV)");
    tLumi->SetNDC();
    tLumi->SetTextAlign(31);
    tLumi->SetTextFont(42);
    tLumi->SetTextSize(0.042);
    tLumi->SetLineWidth(2);
    tLumi->Draw();
    TLatex *tCMS = new TLatex(0.152,0.944,"CMS");
    tCMS->SetNDC();
    tCMS->SetTextAlign(11);
    tCMS->SetTextFont(61);
    tCMS->SetTextSize(0.0525);
    tCMS->SetLineWidth(2);
    tCMS->Draw();
    TLatex *tPrel = new TLatex(0.265,0.944,"Preliminary");
    tPrel->SetNDC();
    tPrel->SetTextAlign(11);
    tPrel->SetTextFont(52);
    tPrel->SetTextSize(0.042);
    tPrel->SetLineWidth(2);
    tPrel->Draw();
    
   c1->Modified();
   c1->cd();
    c1->Update();
   c1->SetSelected(c1);

}
    TGraph*
DrawExpectedBand( TGraph* gr1,  TGraph* gr2, Int_t fillColor, Int_t fillStyle, Int_t cut = 0)
{
    //  TGraph* gr1 = new TGraph( *graph1 );
    //  TGraph* gr2 = new TGraph( *graph2 );

    int number_of_bins = max(gr1->GetN(),gr2->GetN());

    const Int_t gr1N = gr1->GetN();
    const Int_t gr2N = gr2->GetN();

    const Int_t N = number_of_bins;
    Double_t x1[N], y1[N], x2[N], y2[N];

    Double_t xx0, yy0;

    for(int j=0; j<gr1N; j++) {
        gr1->GetPoint(j,xx0,yy0);
        x1[j] = xx0;
        y1[j] = yy0;
    }
    if (gr1N < N) {
        for(int i=gr1N; i<N; i++) {
            x1[i] = x1[gr1N-1];
            y1[i] = y1[gr1N-1];
        }
    }

    Double_t xx1, yy1;

    for(int j=0; j<gr2N; j++) {
        gr2->GetPoint(j,xx1,yy1);
        x2[j] = xx1;
        y2[j] = yy1;
    }
    if (gr2N < N) {
        for(int i=gr2N; i<N; i++) {
            x2[i] = x2[gr1N-1];
            y2[i] = y2[gr1N-1];
        }
    }

    TGraph *grshade = new TGraphAsymmErrors(2*N);
    for (int i=0;i<N;i++) {

        if (x1[i] > cut)
            grshade->SetPoint(i,x1[i],y1[i]);
        //cout<<"grshade x1="<< x1[i] <<" y1="<<y1[i]<<endl;

        if (x2[N-i-1] > cut)
            grshade->SetPoint(N+i,x2[N-i-1],y2[N-i-1]);
    }


    // Apply the cut in the shade plot if there is something that doesn't look good...
    int Nshade = grshade->GetN();
    double x0, y0;
    double x00, y00;

    for(int j=0; j<Nshade; j++) {
        grshade->GetPoint(j,x0,y0);
        if ((x0 != 0) && (y0 != 0)) {
            x00 = x0;
            y00 = y0;
            break;
        }
    }

    for(int j=0; j<Nshade; j++) {
        grshade->GetPoint(j,x0,y0);
        if ((x0 == 0) && (y0 == 0))
            grshade->SetPoint(j,x00,y00);
    }


    // Now draw the plot...
    grshade->SetFillStyle(fillStyle);
    grshade->SetFillColor(fillColor);
    grshade->SetMarkerStyle(21);
    grshade->Draw("F");

    return grshade;
}
///
/// Find an interpolated x value near a certain bin position of a histogram that is the
/// best estimate for h(x)=y. Interpolates by means of fitting a second grade polynomial
/// to up to five adjacent points. Because that's giving us two solutions, we use the central
/// value and knowledge about if it is supposed to be an upper or lower boundary to pick
/// one.
///
/// \param h - the histogram to be interpolated
/// \param i - interpolate around this bin. Must be a bin such that i and i+1 are above and below val
/// \param y - the y position we want to find the interpolated x for
/// \param central - Central value of the solution we're trying to get the CL interval for.
/// \param upper - Set to true if we're computing an upper interval boundary.
/// \param val - Return value: interpolated x position
/// \param err - Return value: estimated interpolation error
/// \return true, if inpterpolation was performed, false, if conditions were not met
///
bool CLIntervalMaker::interpolatePol2fit(const TH1F* h, int i, float y, float central, bool upper,
		float &val, float &err) const
{
	// cout << "CLIntervalMaker::interpolatePol2fit(): i=" << i << " y=" << y << " central=" << central << endl;
	// check if too close to border so we don't have enough bins to fit
	if ( !( 2 <= i && i <= h->GetNbinsX()-1 ) ) return false;
	// check if all necessary bins are on the same side. They are not always,
	// if e.g. in a plugin there's statistical fluctuations
	if ( binsOnSameSide(i-1, y) && binsOnSameSide(i, y) ){
		//cout << "CLIntervalMaker::interpolatePol2fit() : ERROR : bins i-1, i, and i+1 on same side of y" << endl;
		return false;
	}

	// create a TGraph that we can fit
	TGraph *g = new TGraph(3);
	g->SetPoint(0, h->GetBinCenter(i-1), h->GetBinContent(i-1));
	g->SetPoint(1, h->GetBinCenter(i),   h->GetBinContent(i));
	g->SetPoint(2, h->GetBinCenter(i+1), h->GetBinContent(i+1));

	// see if we can add a 4th and 5th point:
	if ( 3 <= i && i <= h->GetNbinsX()-2 ){
		// add a point to the beginning
		if ( (h->GetBinContent(i-2) < h->GetBinContent(i-1) && h->GetBinContent(i-1) < h->GetBinContent(i))
		  || (h->GetBinContent(i-2) > h->GetBinContent(i-1) && h->GetBinContent(i-1) > h->GetBinContent(i)) ){
			TGraph *gNew = new TGraph(g->GetN()+1);
			gNew->SetPoint(0, h->GetBinCenter(i-2), h->GetBinContent(i-2));
			Double_t pointx, pointy;
			for ( int i=0; i<g->GetN(); i++ ){
				g->GetPoint(i, pointx, pointy);
				gNew->SetPoint(i+1, pointx, pointy);
			}
			delete g;
			g = gNew;
		}
		// add a point to the end
		if ( (h->GetBinContent(i+2) < h->GetBinContent(i+1) && h->GetBinContent(i+1) < h->GetBinContent(i))
		  || (h->GetBinContent(i+2) > h->GetBinContent(i+1) && h->GetBinContent(i+1) > h->GetBinContent(i)) ){
			g->Set(g->GetN()+1);
			g->SetPoint(g->GetN()-1, h->GetBinCenter(i+2), h->GetBinContent(i+2));
		}
	}

	// debug: show fitted 1-CL histogram
	// if ( y<0.1 )
	// // if ( methodName == TString("Plugin") && y<0.1 )
	// {
	//   // TString debugTitle = methodName + Form(" y=%.2f ",y);
	//   // debugTitle += upper?Form("%f upper",central):Form("%f lower",central);
	// 		TString debugTitle = "honk";
	//   TCanvas *c = newNoWarnTCanvas(getUniqueRootName(), debugTitle);
	//   g->SetMarkerStyle(3);
	//   g->SetHistogram(const_cast<TH1F*>(h));
	//   const_cast<TH1F*>(h)->Draw();
	//   g->DrawClone("p");
	// }

	// fit
	TF1 *f1 = new TF1("f1", "pol2", h->GetBinCenter(i-2), h->GetBinCenter(i+2));
	g->Fit("f1", "q");    // fit linear to get decent start parameters
	g->Fit("f1", "qf+");  // refit with minuit to get more correct errors (TGraph fit errors bug)
	float p[3], e[3];
	for ( int ii=0; ii<3; ii++ ){
		p[ii] = f1->GetParameter(ii);
		e[ii] = f1->GetParError(ii);
	}

	// get solution by solving the pol2 for x
	float sol0 = pq(p[0], p[1], p[2], y, 0);
	float sol1 = pq(p[0], p[1], p[2], y, 1);

	// decide which of both solutions to use based on the position of
	// the central value
	// \todo we probably don't need the central value to decide which solution
	// to use. Just take the one closest to the original bin! Can't think of a
	// situation where this should fail. So we don't need the central value in
	// this method at all, to be removed.
	int useSol = 0;
	//if ( (sol0<central && sol1>central) || (sol1<central && sol0>central) ){
		//if ( upper ){
			//if ( sol0<sol1 ) useSol = 1;
			//else             useSol = 0;
		//}
		//else{
			//if ( sol0<sol1 ) useSol = 0;
			//else             useSol = 1;
		//}
	//}
	//else{
		if ( fabs(h->GetBinCenter(i)-sol0) < fabs(h->GetBinCenter(i)-sol1) ) useSol = 0;
		else useSol = 1;
	//}
	if ( useSol==0 ) val = sol0;
	else             val = sol1;

	// try error propagation: sth is wrong in the formulae
	// float err0 = TMath::Max(sq(val-pq(p[0]+e[0], p[1], p[2], y, useSol)), sq(val-pq(p[0]-e[0], p[1], p[2], y, useSol)));
	// float err1 = TMath::Max(sq(val-pq(p[0], p[1]+e[1], p[2], y, useSol)), sq(val-pq(p[0], p[1]-e[1], p[2], y, useSol)));
	// float err2 = TMath::Max(sq(val-pq(p[0], p[1], p[2]+e[2], y, useSol)), sq(val-pq(p[0], p[1], p[2]-e[2], y, useSol)));
	// err = sqrt(err0+err1+err2);
	// printf("%f %f %f\n", val, pq(p[0]+e[0], p[1], p[2], y, useSol), pq(p[0]-e[0], p[1], p[2], y, useSol));
	// printf("%f %f %f\n", val, pq(p[0], p[1]+e[1], p[2], y, useSol), pq(p[0], p[1]-e[1], p[2], y, useSol));
	// printf("%f %f %f\n", val, pq(p[0], p[1], p[2]+e[2], y, useSol), pq(p[0], p[1], p[2]-e[2], y, useSol));
	err = 0.0;
	delete g;
	return true;
}
//____________________________________________________________________________________
// Plot blue band (SM Higgs curve)
void blueBand( )
{

  double zerror = 4;
  double xmin = 76;

  int npoints = 31;
  double x[] = { 10.000000, 11.392849, 12.979700, 14.787576, 16.847262, 19.193831, 21.867241, 
                 24.913018, 28.383024, 32.336350, 36.840315, 41.971614, 47.817625, 54.477897,
                 62.065844, 70.710678, 76, 80.559606, 91.780341, 104.563955, 119.128133, 135.720881,
                 154.624747, 176.161637, 200.698289, 228.652526, 260.500365, 296.784127, 
                 338.121669, 385.216905, 438.871795, 500.000000 };

  double y[] = { 20.929260, 18.757168, 16.647426, 14.611732, 12.661571, 10.808107, 9.062193,
                 7.434501, 5.935701, 4.576664, 3.368675, 2.323612, 1.454084, 0.776111,
                 0.300018, 0.042673, 0.0001, 0.020469, 0.251087, 0.750519, 1.538231, 2.633789,
                 4.056692, 5.826546, 7.962673, 10.483595, 13.406320, 16.745357, 20.511276,
                 24.717583, 29.345917, 34.380810 };


  TGraph* smGraph = new TGraph( npoints, x, y );

  if ( npoints > MAXPOINTS ) {
    std::cerr << "FATAL: npoints = " << npoints << " is greater than MAXPOINTS" << std::endl;
    exit(-1);
  }
  double x1[2*MAXPOINTS], y1[2*MAXPOINTS];
  double x2[MAXPOINTS], y2[MAXPOINTS];

  // Find mH at minimum
  int i1=0; // iterator for upper curve
  int i2=0; // iterator for lower curve
  double x0,y0;
  double step = 5;
  smGraph->GetPoint( 0, x0, y0 );
  for ( int i=0; i<100; ++i )
    {
      double ix = x0+i*step;
      double iy = smGraph->Eval( ix, 0, "S" );
      double error = TMath::Log( ix/12. )*3.;
      if ( ix<=xmin-error ) { 
        x1[i1] = ix+error; y1[i1]=iy; ++i1; 
        x2[i2] = ix-error; y2[i2]=iy; ++i2;
      }
      else if ( ix>=xmin+error) { 
        x1[i1] = ix-error; y1[i1]=iy; ++i1; 
        x2[i2] = ix+error; y2[i2]=iy; ++i2;
      } else {//if ( iy>0. ) {
        x2[i2] = (ix<=xmin)?ix-error:ix+error; 
        y2[i2]=iy; 
        ++i2;
      }
      
    }
  // Merge arrays
  for ( int i=0; i<i2; ++i ) {
    x1[i+i1] = x2[i2-i-1];
    y1[i+i1] = y2[i2-i-1];
  }
  if ( doBands ) {
    TGraph* blueBand = new TGraph( i1+i2, x1, y1 );
    blueBand->SetFillColor(7);
    blueBand->SetLineColor(7);
    blueBand->Draw("LF");
    blueBand->Draw("C");
  } else {
    smGraph->SetLineWidth(5);
  }

  smGraph->SetLineColor(4);
  smGraph->Draw("C");
  double chi2limit = smGraph->Eval( LEPLIMIT, 0, "S" );
  std::cout << "Value at limit (" << LEPLIMIT << "): " << chi2limit << std::endl;

  TGraph* lowband = new TGraph( i2, x2, y2 );
  std::cout << "Value of (low) blueband at limit: " << lowband->Eval( LEPLIMIT, 0, "S" )
            << std::endl;

}
Example #26
0
int main( int argc, char* argv[] ) {

  if( argc!=3 && argc!=4 ) {
    std::cout << "USAGE: ./draw_golfcourse [(string)data_dataset] [data_mc] [nbtags=\"ALL\"]" << std::endl;
    exit(23);
  }
  

  std::string data_dataset(argv[1]);

  std::string data_mc(argv[2]);

  int nbtags=-1;
  if( argc==4 ) {
    nbtags = atoi(argv[3]);
  }


  TString data_dataset_tstr(data_dataset);
  std::string PUType = "Run2011A";
  float lumi = 2100.;
  if( data_dataset=="HR11" ) {
    PUType = "HR11";
    lumi = 4200.;
  } else if( data_dataset=="HR11_v2" ) {
    PUType = "HR11_73pb";
    lumi = 4600.;
  } if( data_dataset_tstr.BeginsWith("Run2011B") ) {
    PUType = "Run2011B";
  }

  DrawBase* db = new DrawBase("Golfcourse");
  db->set_lumiNormalization(lumi);
  std::string dataFileName = "HZZlljjRM_DATA_" + data_dataset + "_optLD_looseBTags_v2_ALL.root";
  TFile* file_data = TFile::Open(dataFileName.c_str());
  db->add_dataFile( file_data, "data" );

  //db->set_isCMSArticle(true);

  TGraph* graphObserved = get_observedLimit( data_dataset, data_mc, nbtags );

  graphObserved->SetMarkerStyle(21);
  graphObserved->SetMarkerSize(.85);
  graphObserved->SetLineWidth(3.);
  //graphObserved->SetMarkerColor(kGreen+4);
  //graphObserved->SetMarkerSize(1.);

  std::pair<TGraphAsymmErrors*,TGraphAsymmErrors*> graphs_expected = get_expectedLimit( data_dataset, data_mc, nbtags );
  TGraphAsymmErrors* graphExpected68 = graphs_expected.first;
  TGraphAsymmErrors* graphExpected95 = graphs_expected.second;

  TGraphAsymmErrors* graphExpected68_forLegend = new TGraphAsymmErrors(*graphExpected68);
  graphExpected68_forLegend->SetFillColor(kGreen);

  graphExpected68->SetFillColor(kGreen);
  graphExpected68->SetLineColor(kBlack);
  graphExpected68->SetLineStyle(2);
  graphExpected68->SetLineWidth(2);
  graphExpected68->SetFillStyle(1001);//solid

  graphExpected95->SetFillColor(kYellow);
  graphExpected95->SetFillStyle(1001);//solid

  float xmin = 180.;
  float xmax = 620.;

  float yMax = 8.;
  if( data_dataset=="Run2011A_FULL" ) yMax = 10.;
  if( nbtags!=-1 ) yMax=12.;

  TH2D* axes = new TH2D("axes", "", 10, xmin, xmax, 10, 0., yMax );
  axes->SetXTitle("m_{H} [GeV]");
  axes->SetYTitle("#sigma_{95%} / #sigma_{SM}");

  //TPaveText* labelCMS = get_labelCMS(db);
  TPaveText* labelCMS = db->get_labelCMS();
  TPaveText* labelSqrt = db->get_labelSqrt();


  TLine* line_one = new TLine( xmin, 1., xmax, 1.);
  line_one->SetLineColor(kRed);
  line_one->SetLineWidth(2);

  char legendTitle[200];
  sprintf( legendTitle, "%d b-tag Category", nbtags );

  TLegend* legend;
  if( nbtags!=-1 ) 
    legend = new TLegend( 0.35, 0.6, 0.85, 0.90, legendTitle );
  else
    legend = new TLegend( 0.35, 0.6, 0.85, 0.90);
  legend->SetFillColor(10);
  legend->SetFillStyle(1001);
  legend->SetBorderSize(1);
  legend->SetTextSize(0.034);
  legend->SetTextFont(42);
  legend->AddEntry( graphExpected68, "Bayesian Expected", "L" ); 
  legend->AddEntry( graphExpected68_forLegend, "Expected #pm 1#sigma", "F" ); 
  legend->AddEntry( graphExpected95, "Expected #pm 2#sigma", "F" ); 
  legend->AddEntry( line_one, "SM", "L" ); 

  TCanvas* c1 = new TCanvas("c1", "", 630, 600);
  c1->SetGrid(true);
  c1->cd();
  axes->Draw("AXIS");
  labelCMS->Draw("same");
  labelSqrt->Draw("same");
  graphExpected95->Draw("3same");
  graphExpected68->Draw("3same");
  graphExpected68->Draw("LXsame");
  gPad->RedrawAxis();
  line_one->Draw("same");
  legend->Draw("same");

  char canvasName[500];
  if( nbtags>=0 )
    sprintf( canvasName, "datacards_%s_fit%s/upperLimitExpected_%s_%dbtag.eps", data_dataset.c_str(), data_mc.c_str(), data_dataset.c_str(), nbtags );
  else
    sprintf( canvasName, "datacards_%s_fit%s/upperLimitExpected_%s.eps", data_dataset.c_str(), data_mc.c_str(), data_dataset.c_str() );
  c1->SaveAs(canvasName);


  c1->Clear();

  // now also observed:

  TLegend* legend2;
  if( nbtags!=-1 ) 
    legend2 = new TLegend( 0.35, 0.6, 0.85, 0.90, legendTitle );
  else
    legend2 = new TLegend( 0.35, 0.6, 0.85, 0.90);
  legend2->SetFillColor(10);
  legend2->SetFillStyle(1001);
  legend2->SetBorderSize(1);
  legend2->SetTextSize(0.034);
  legend2->SetTextFont(42);
  legend2->AddEntry( graphObserved, "Bayesian Observed", "LP" ); 
  legend2->AddEntry( graphExpected68, "Bayesian Expected", "L" ); 
  legend2->AddEntry( graphExpected68_forLegend, "Expected #pm 1#sigma", "F" ); 
  legend2->AddEntry( graphExpected95, "Expected #pm 2#sigma", "F" ); 
  legend2->AddEntry( line_one, "SM", "L" ); 


  axes->Draw();
  labelCMS->Draw("same");
  labelSqrt->Draw("same");
  graphExpected95->Draw("3same");
  graphExpected68->Draw("3same");
  graphExpected68->Draw("LXsame");
  gPad->RedrawAxis();
  line_one->Draw("same");
  graphObserved->Draw("PLsame");
  legend2->Draw("same");

  if( nbtags>=0 )
    sprintf( canvasName, "datacards_%s_fit%s/upperLimit_%s_%dbtag.eps", data_dataset.c_str(), data_mc.c_str(), data_dataset.c_str(), nbtags );
  else
    sprintf( canvasName, "datacards_%s_fit%s/upperLimit_%s.eps", data_dataset.c_str(), data_mc.c_str(), data_dataset.c_str() );
  c1->SaveAs(canvasName);


  char expectedLimitFileName[300];
  if( nbtags>=0 )
    sprintf( expectedLimitFileName, "datacards_%s_fit%s/expectedLimit_%s_%dbtag.txt", data_dataset.c_str(), data_mc.c_str(), data_dataset.c_str(), nbtags );
  else
    sprintf( expectedLimitFileName, "datacards_%s_fit%s/expectedLimit_%s.txt", data_dataset.c_str(), data_mc.c_str(), data_dataset.c_str() );
  ofstream ofs_expected(expectedLimitFileName);
  ofs_expected << "mH\tmedian\tlow95\tlow68\tup68\tup95" << std::endl;
  for( unsigned imass=0; imass<graphExpected95->GetN(); ++imass ) {
    Double_t mass, expectedUL;
    graphExpected95->GetPoint( imass, mass, expectedUL );
    float up95 = graphExpected95->GetErrorYhigh( imass );
    float up68 = graphExpected68->GetErrorYhigh( imass );
    float low95 = graphExpected95->GetErrorYlow( imass );
    float low68 = graphExpected68->GetErrorYlow( imass );
    ofs_expected << mass << "\t" << expectedUL << "\t" << low95 << "\t" << low68 << "\t" << up68 << "\t" << up95 << std::endl;
  }
  ofs_expected.close();

  char observedLimitFileName[300];
  if( nbtags>=0 )
    sprintf( observedLimitFileName, "datacards_%s_fit%s/observedLimit_%s_%dbtag.txt", data_dataset.c_str(), data_mc.c_str(), data_dataset.c_str(), nbtags );
  else
    sprintf( observedLimitFileName, "datacards_%s_fit%s/observedLimit_%s.txt", data_dataset.c_str(), data_mc.c_str(), data_dataset.c_str() );
  ofstream ofs_observed(observedLimitFileName);
  ofs_observed << "mH\tobservedLimit" << std::endl;
  for( unsigned imass=0; imass<graphObserved->GetN(); ++imass ) {
    Double_t mass, observedUL;
    graphObserved->GetPoint( imass, mass, observedUL );
    ofs_observed << mass << "\t" << observedUL << std::endl;
  }
  ofs_observed.close();


  return 0;


}