Beispiel #1
0
bool inPatterns(const std::string& test, const char* patterns)
{
  std::vector<std::string> samples;
  string2Vector(cleanupWhitespaces(patterns), samples);
  for(std::vector<std::string>::const_iterator sample = samples.begin(); sample!=samples.end(); ++sample){
    TRegexp matcher(sample->c_str(), true);  // true = make it "glob-style" i.e. "*" instead of ".*"
    if(TString(test).Index(matcher) > -1){
      return true;
    }
  }
  return false;
}
void plotModelindependentTanb(const char* filename, const char* channelstr, bool expected, bool observed, double minimum=0., double maximum=20., const char* label="CMS Preliminary,  H#rightarrow#tau#tau,  4.9 fb^{-1} at 7 TeV, 19.4 fb^{-1} at 8 TeV")
{
  SetStyle();

  std::map<std::string, unsigned int> colors;
  colors["BR0p1"  ] = kBlue;
  colors["BR0p2"  ] = kGreen;
  colors["BR0p3"  ] = kRed;

  std::cout << " *******************************************************************************************************\n"
	    << " * Usage     : root -l                                                                                  \n"
	    << " *             .x MitLimits/Higgs2Tau/macros/compareLimits.C+(file, chn, exp, obs, type, min, max, log) \n"
	    << " *                                                                                                      \n"
	    << " * Arguments :  + file     const char*      full path to the input file                                 \n"
	    << " *                                                                                                      \n"
	    << " *              + chn      const char*      list of BR please order correct high to low or low to high  \n"
	    << " *                                                                                                      \n"
	    << " *              + exp      bool             compare expected limits                                     \n"
	    << " *                                                                                                      \n"
	    << " *              + obs      bool             compare observed limits                                     \n"
	    << " *                                                                                                      \n"
	    << " *              + max      double           maximum of the plot (default is 20.)                        \n"
	    << " *                                                                                                      \n"
	    << " *              + min      double           minimum of the plot (default is  0.)                        \n"
	    << " *                                                                                                      \n"
	    << " *******************************************************************************************************\n";

  /// open input file  
  TFile* inputFile = new TFile(filename); if(inputFile->IsZombie()){ std::cout << "ERROR:: file: " << filename << " does not exist.\n"; }

  /// prepare input parameters
  std::vector<std::string> channels;
  string2Vector(cleanupWhitespaces(channelstr), channels);

  /// prepare histograms
  std::vector<TGraph*> hobs, hexp;
  for(int i=0; i<channels.size(); ++i){
    if(observed) hobs.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/observed").c_str()));
    if(expected) hexp.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/expected").c_str()));
  }
  
  double x1, x2, y1, y2;
  TGraphAsymmErrors* Texp = 0;
  if(expected){
    Texp = new TGraphAsymmErrors();
    //Texp->SetPoint(0, 0, 0);
    //Texp->SetPointEYlow (0, 0);
    //Texp->SetPointEYhigh(0, 100); 
    for(int i=0; i<hexp[0]->GetN(); i++){
      hexp[0]            ->GetPoint(i, x1, y1);
      hexp[hexp.size()-1]->GetPoint(i, x2, y2);
      Texp               ->SetPoint(i, x1, y1); 
      if(y1<y2){
	Texp->SetPointEYlow (i, 0);
	Texp->SetPointEYhigh(i, y2-y1);
      }
      else{
	Texp->SetPointEYlow (i, y1-y2);
	Texp->SetPointEYhigh(i, 0);
      }
    }
  }
  
  TGraphAsymmErrors* Tobs = 0;
  if(observed){
    Tobs = new TGraphAsymmErrors();
    //Tobs->SetPoint(0, 0, 100.);
    //Tobs->SetPointEYlow (0, 0);
    //Tobs->SetPointEYhigh(0, 100); 
    for(int i=0; i<hobs[0]->GetN(); i++){
      hobs[0]            ->GetPoint(i, x1, y1);
      hobs[hexp.size()-1]->GetPoint(i, x2, y2);
      Tobs               ->SetPoint(i, x1, y1); 
      if(y1<y2){
	Tobs->SetPointEYlow (i, 0);
	Tobs->SetPointEYhigh(i, y2-y1);
      }
      else{
	Tobs->SetPointEYlow (i, y1-y2);
	Tobs->SetPointEYhigh(i, 0);
      }
    }
  }

  /// do the drawing


  TCanvas* canv1 = new TCanvas("canv1", "Limit Comparison", 600, 600);
  canv1->cd();
  canv1->SetGridx(1);
  canv1->SetGridy(1);

  bool firstPlot=true;
  for(unsigned int i=0; i<hexp.size(); ++i){
    if(firstPlot){
      hexp[i]->SetMaximum(maximum);
      hexp[i]->SetMinimum(minimum);

      // format x-axis
      std::string x_title = std::string("m_{A} [GeV]");
      hexp[i]->GetXaxis()->SetTitle(x_title.c_str());
      hexp[i]->GetXaxis()->SetLabelFont(62);
      hexp[i]->GetXaxis()->SetTitleFont(62);
      hexp[i]->GetXaxis()->SetTitleColor(1);
      hexp[i]->GetXaxis()->SetTitleOffset(1.05);
      hexp[i]->GetYaxis()->SetRangeUser(0,maximum);

      // format y-axis
      std::string y_title = std::string("#bf{tan#beta}");
      hexp[i]->GetYaxis()->SetTitle(y_title.c_str());
      hexp[i]->GetYaxis()->SetLabelFont(62);
      hexp[i]->GetYaxis()->SetTitleOffset(1.05);
      hexp[i]->GetYaxis()->SetLabelSize(0.03);
      hexp[i]->GetXaxis()->SetLimits(hexp[i]->GetX()[0]-.1, hexp[i]->GetX()[hexp[i]->GetN()-1]+.1);
      //hexp[i]->GetXaxis()->SetRangeUser(90,250);
    }
    hexp[i]->SetLineStyle( 1.);
    hexp[i]->SetLineWidth( 4.); 
    hexp[i]->SetLineColor(colors.find(channels[i])->second);
    //hexp[i]->SetMarkerStyle(20);
    //hexp[i]->SetMarkerSize(MARKER_SIZE);
    //hexp[i]->SetMarkerColor(colors.find(channels[i])->second);
    //hexp[i]->Draw(firstPlot ? "APL" : "PLsame");
    hexp[i]->Draw(firstPlot ? "AL" : "Lsame");
    firstPlot=false;
  }
  for(unsigned int i=0; i<hobs.size(); ++i){
    if(firstPlot){
      hobs[i]->SetMaximum(maximum);
      hobs[i]->SetMinimum(minimum);
   
      // format x-axis
      std::string x_title = std::string("m_{A} [GeV]");
      hobs[i]->GetXaxis()->SetTitle(x_title.c_str());
      hobs[i]->GetXaxis()->SetLabelFont(62);
      hobs[i]->GetXaxis()->SetTitleFont(62);
      hobs[i]->GetXaxis()->SetTitleColor(1);
      hobs[i]->GetXaxis()->SetTitleOffset(1.05);
      hobs[i]->GetYaxis()->SetRangeUser(0,maximum);
      
      // format y-axis
      std::string y_title = std::string("#bf{tan#beta}");
      hobs[i]->GetYaxis()->SetTitle(y_title.c_str());
      hobs[i]->GetYaxis()->SetLabelFont(62);
      hobs[i]->GetYaxis()->SetTitleOffset(1.05);
      hobs[i]->GetYaxis()->SetLabelSize(0.03);
      hobs[i]->GetXaxis()->SetLimits(hobs[i]->GetX()[0]-.1, hobs[i]->GetX()[hobs[i]->GetN()-1]+.1);
      //hobs[i]->GetXaxis()->SetRangeUser(90,250);
    }
    hobs[i]->SetLineStyle( 1.);
    hobs[i]->SetLineWidth( 4.); 
    hobs[i]->SetLineColor(colors.find(channels[i])->second);
    //hobs[i]->SetMarkerStyle(20);
    //hobs[i]->SetMarkerSize(MARKER_SIZE);
    //hobs[i]->SetMarkerColor(colors.find(channels[i])->second);
    //hobs[i]->Draw(firstPlot ? "APL" : "PLsame");
    hobs[i]->Draw(firstPlot ? "AL" : "Lsame");
    firstPlot=false;
  }
  canv1->RedrawAxis();

  if(expected){
    Texp->SetFillStyle(1001.);
    Texp->SetFillColor(kGray);
    Texp->Draw("3");    
  }

  if(observed){
    Tobs->SetFillStyle(1001.);
    Tobs->SetFillColor(kCyan);
    Tobs->Draw("3same"); 
  }
  
  canv1->RedrawAxis();

  TLegend* leg1 = new TLegend(0.1, 0.65, 0.5, 0.9);
  CMSPrelim(label, "", 0.15, 0.835);
  //leg1->SetTextSize(0.025);
  leg1->SetBorderSize( 0 );
  leg1->SetFillStyle ( 1001 );
  //leg1->SetFillColor ( 0 );
  leg1->SetFillColor (kWhite);
  leg1->SetHeader("95% CL excluded");
  if(expected){
    for(unsigned int i=0; i<hexp.size(); ++i){
      leg1->AddEntry( hexp[i] , channel(channels[i]) ? legendEntry(channels[i]).c_str() : legendEntry(channels[i]).append("-Channel").c_str(),  "L" );
    }
    leg1->AddEntry( Texp , "limits in between", "F" );
  }
  if(observed && !expected){
    for(unsigned int i=0; i<hobs.size(); ++i){
      leg1->AddEntry( hobs[i] , channel(channels[i]) ? legendEntry(channels[i]).c_str() : legendEntry(channels[i]).append("-Channel").c_str(),  "L" );
    }
    leg1->AddEntry( Tobs , "limits in between", "F" );
  }
  leg1->Draw("same");

  canv1->Print("tanb.pdf");
  canv1->Print("tanb.png");
  canv1->Print("tanb.eps");
  return;
}
void compareShapes(std::string path, const char* channelstr, const char* periodstr, std::string type, std::string category, const char* shapestr1, const char* shapestr2, double minimum=0., double maximum=20., bool log=false, const char* label=" Preliminary, H#rightarrow#tau#tau, L=24.3 fb^{-1}")
{
  SetStyle();

  std::map<std::string, unsigned int> colors;
  colors["incl"       ] = kBlue;
  colors["0jet"       ] = kBlue;
  colors["0jet-mvis"  ] = kBlue+2;
  colors["0jet-ichep" ] = kBlue+2;
  colors["2jet"       ] = kMagenta;
  colors["vbf"        ] = kRed;
  colors["vbf+0jet"   ] = kRed;
  colors["vbf-mvis"   ] = kRed+2;
  colors["vbf-ichep"  ] = kRed+2;
  colors["boost"      ] = kGreen;
  colors["boost+0jet" ] = kGreen;
  colors["boost-mvis" ] = kGreen+2;
  colors["boost-ichep"] = kGreen+2;
  colors["btag"       ] = kRed;
  colors["nobtag"     ] = kBlue;
  colors["emu"        ] = kBlue;
  colors["em"         ] = kBlue;
  colors["em-mvis"    ] = kBlue+2;
  colors["em-ichep"   ] = kBlue+2;
  colors["etau"       ] = kRed;
  colors["et"         ] = kRed;
  colors["et-mvis"    ] = kRed+2;
  colors["et-ichep"   ] = kRed+2;
  colors["mutau"      ] = kGreen;
  colors["mt"         ] = kGreen;
  colors["mt-mvis"    ] = kGreen+2;
  colors["mt-ichep"   ] = kGreen+2;
  colors["mumu"       ] = kMagenta;
  colors["mm"         ] = kMagenta;
  colors["mm-mvis"    ] = kMagenta+2;
  colors["mm-ichep"   ] = kMagenta+2;
  colors["tautau"     ] = kOrange;
  colors["tt"         ] = kOrange;
  colors["tt-mvis"    ] = kOrange+2;
  colors["tt-ichep"   ] = kOrange+2;
  colors["vhtt"       ] = kMagenta+2;
  colors["whtt"       ] = kMagenta+0;
  colors["zhtt"       ] = kCyan+2;
  colors["whhh"       ] = kBlue;
  colors["cmb"        ] = kBlack;
  colors["cmb-mvis"   ] = kGray+2;
  colors["cmb-ichep"  ] = kGray+3;
  colors["cmb+"       ] = kGray+2;
  colors["htt"        ] = kBlack;
  colors["htt+"       ] = kBlue;
  colors["hgg"        ] = kRed;
  colors["hww"        ] = kGreen;
  colors["hbb"        ] = kOrange;
  colors["hmm"        ] = kViolet;
  colors["4l"         ] = kGreen;
  colors["llt"        ] = kRed;
  colors["ltt"        ] = kBlue;
  colors["hzz4l"      ] = kBlue;
  colors["hzz2l2q"    ] = kMagenta;
  colors["hzz2l2q+"   ] = kMagenta;
  colors["hzz2l2t"    ] = kOrange;
  colors["hzz2l2n"    ] = kPink;
  colors["ggH"        ] = kRed;
  colors["bbH"        ] = kBlue;
  colors["mvis"       ] = kBlue+2;
  colors["ichep"      ] = kBlue+2;
  colors["test-0"     ] = kRed+2;
  colors["test-1"     ] = kGreen+2;
  colors["test-2"     ] = kGreen;
  colors["test-3"     ] = kRed+2;
  colors["test-4"     ] = kBlue;
  colors["test-5"     ] = kViolet-6;
  colors["old"        ] = kViolet-6;
  colors["cmb-5fb"    ] = kBlue;
  colors["hpa-5fb"    ] = kRed;
  colors["hpa-10fb"   ] = kBlack;
  colors["saeff"      ] = kGreen;
  colors["gluph"      ] = kOrange-3;
  colors["nomix-200"  ] = kBlue-10;
  colors["nomix+200"  ] = kBlue +2;
  colors["mhmax-400"  ] = kGray +2;
  colors["mhmax-200"  ] = kGray +1;
  colors["mhmax+200"  ] = kMagenta+ 4;
  colors["mhmax+400"  ] = kMagenta+ 3;
  colors["mhmax+600"  ] = kMagenta- 2;
  colors["mhmax+800"  ] = kMagenta-10;
  colors["MSSM-7TeV"  ] = kBlue+2;
  colors["MSSM-8TeV"  ] = kBlue+4;
  colors["HIG-11-020" ] = kBlue+2;
  colors["HIG-11-029" ] = kRed+2;
  colors["HIG-12-018" ] = kBlue;
  colors["HIG-12-032" ] = kRed+2;
  colors["HIG-12-043" ] = kBlack;
  colors["HIG-12-050" ] = kBlack;


  std::cout << " *******************************************************************************************************\n"
	    << " * Usage     : root -l                                                                                  \n"
	    << " *             .x MitLimits/Higgs2Tau/macros/compareShapes.C+(file, category, shape1, shape2, max, min) \n"
	    << " *                                                                                                      \n"
	    << " * Arguments :  + path     string           path to directory where files are stored                    \n"
	    << " *                                          must be 'common' directory                                  \n"
            << " *              + chn      const char*      channels to be combined                                     \n"
	    << " *              + per      const char*      periods to be combined                                      \n"
	    << " *              + type     string           'mssm' or 'sm'                                              \n"
	    << " *              + category string           choose which category should be compared,                   \n"
	    << " *                                          e.g. btag, nobtag                                           \n"
	    << " *              + shape1   const char*      list of shapes to be compared to shape2                     \n"
	    << " *                                          The list should be comma separated and may contain          \n"
	    << " *                                          whitespaces                                                 \n"
	    << " *              + shape2   const char*      list of shapes to be compared to shape1                     \n"
	    << " *                                          The list should be comma separated and may contain          \n"
	    << " *                                          whitespaces                                                 \n"
	    << " *              + max       double          maximum of the plot (default is 20.)                        \n"
	    << " *                                                                                                      \n"
	    << " *              + min       double          minimum of the plot (default is  0.)                        \n"
	    << " *                                                                                                      \n"
	    << " *              + log       bool            set log scale yes or no (default is false)                  \n"
	    << " *                                                                                                      \n"
	    << " *******************************************************************************************************\n";


  /// prepare input parameters
  std::vector<std::string> shape1;
  string2Vector(cleanupWhitespaces(shapestr1), shape1);
  std::vector<std::string> shape2;
  string2Vector(cleanupWhitespaces(shapestr2), shape2); 
  std::vector<std::string> channels;
  string2Vector(cleanupWhitespaces(channelstr), channels);
  std::vector<std::string> periods;
  string2Vector(cleanupWhitespaces(periodstr), periods);

  /// test input files 
  std::vector<std::string> filenames;
  for(unsigned k=0; k<channels.size(); k++){
      for(unsigned i=0; i<periods.size(); i++){
	 if(type=="mssm"){    
	   filenames.push_back(std::string(path+"/"+"htt_"+channels[k]+".inputs-mssm-"+periods[i]+"-0.root"));
	 }
	 else{
	   filenames.push_back(std::string(path+"/"+"htt_"+channels[k]+".input_"+periods[i]+".root"));
	 }
      }
  }
 

  for(unsigned i=0; i<filenames.size(); i++){
      TFile* inputFile = new TFile(filenames[i].c_str()); 
      if(inputFile->IsZombie()){ 
	std::cout << "ERROR:: file: " << filenames[i] << " does not exist -> Will be removed from list of files." << std::endl; 
	filenames.erase(filenames.begin()+i);
      }
  }
  
  for(unsigned i=0; i<filenames.size(); i++){
      TFile* inputFile = new TFile(filenames[i].c_str()); 
      if(inputFile->IsZombie()){ 
	std::cout << "ERROR:: file: " << filenames[i] << " does not exist -> Will be removed from list of files." << std::endl; 
	filenames.erase(filenames.begin()+i);
      }
  }
  
  std::vector<TH1F*> hshape1;
  std::vector<TH1F*> hshape2;
  for(unsigned k=0; k<filenames.size(); k++){
      TFile* inputFile = new TFile(filenames[k].c_str()); 
      /// prepare histograms
      for(unsigned i=0; i<shape1.size(); ++i){
	if(filenames[k].find("_em")!=std::string::npos) hshape1.push_back(get<TH1F>(inputFile, std::string("emu_"+category+"/").append(shape1[i]).c_str()));
	if(filenames[k].find("_et")!=std::string::npos) hshape1.push_back(get<TH1F>(inputFile, std::string("eleTau_"+category+"/").append(shape1[i]).c_str()));
	if(filenames[k].find("_mm")!=std::string::npos) hshape1.push_back(get<TH1F>(inputFile, std::string("mumu_"+category+"/").append(shape1[i]).c_str()));
	if(filenames[k].find("_mt")!=std::string::npos) hshape1.push_back(get<TH1F>(inputFile, std::string("muTau_"+category+"/").append(shape1[i]).c_str()));
	if(filenames[k].find("_tt")!=std::string::npos) hshape1.push_back(get<TH1F>(inputFile, std::string("tauTau"+category+"/").append(shape1[i]).c_str()));		   	       
      }
      for(unsigned i=0; i<shape2.size(); ++i){
	if(filenames[k].find("_em")!=std::string::npos) hshape2.push_back(get<TH1F>(inputFile, std::string("emu_"+category+"/").append(shape2[i]).c_str()));
	if(filenames[k].find("_et")!=std::string::npos) hshape2.push_back(get<TH1F>(inputFile, std::string("eleTau_"+category+"/").append(shape2[i]).c_str()));
	if(filenames[k].find("_mm")!=std::string::npos) hshape2.push_back(get<TH1F>(inputFile, std::string("mumu_"+category+"/").append(shape2[i]).c_str()));
	if(filenames[k].find("_mt")!=std::string::npos) hshape2.push_back(get<TH1F>(inputFile, std::string("muTau_"+category+"/").append(shape2[i]).c_str()));
	if(filenames[k].find("_tt")!=std::string::npos) hshape2.push_back(get<TH1F>(inputFile, std::string("tauTau"+category+"/").append(shape2[i]).c_str()));

      }
  }


  /// do the drawing
  TCanvas* canv1 = new TCanvas("canv1", "Absolute Comparison", 600, 600);
  canv1->cd();
  canv1->SetGridx(1);
  canv1->SetGridy(1);
 
  bool firstPlot=true;
  for(unsigned int i=0; i<hshape1.size(); ++i){
    if(firstPlot){
      if(log){ canv1->SetLogy(1); }
      // format x-axis
      std::string x_title;
      //x_title = std::string("#sigma#timesBR/#sigma#timesBR_{SM}");
      x_title = std::string("m_{#tau#tau}");
      hshape1[i]->SetXTitle(x_title.c_str());
      hshape1[i]->GetXaxis()->SetTitleFont(62);
      hshape1[i]->GetXaxis()->SetLabelFont(62);
      hshape1[i]->GetXaxis()->SetTitleColor(1);
      hshape1[i]->GetXaxis()->SetTitleOffset(1.05);

      // format y-axis
      std::string y_title;
      y_title = std::string("arbitary numbers"); 
      hshape1[i]->SetYTitle(y_title.c_str());
      hshape1[i]->GetXaxis()->SetTitleFont(62);
      hshape1[i]->GetYaxis()->SetLabelFont(62);
      //hshape1[i]->GetYaxis()->SetTitleSize(0.05);
      hshape1[i]->GetYaxis()->SetTitleOffset(1.05);
      hshape1[i]->GetYaxis()->SetLabelSize(0.03);
      hshape1[i]->GetXaxis()->SetRangeUser(0,400);
      hshape1[i]->SetMaximum(maximum);
      hshape1[i]->SetMinimum(minimum);
      }  
    hshape1[i]->SetLineStyle(1.);
    hshape1[i]->SetLineWidth(2.); 
    hshape1[i]->SetLineColor(kBlue); 
    //hshape1[i]->SetMarkerStyle(20);
    //hshape1[i]->SetMarkerSize(MARKER_SIZE);
    //hshape1[i]->SetMarkerColor(kBlue);
    firstPlot=false;  
    if(i>0) hshape1[0]->Add(hshape1[i]);
  }
  hshape1[0]->Scale(1/hshape1[0]->Integral());
  //hshape1[0]->SetMaximum(maximum);
  //hshape1[0]->SetMinimum(minimum);
  hshape1[0]->SetTitle("");
  hshape1[0]->Draw("h");

  firstPlot=true;
  for(unsigned int i=0; i<hshape2.size(); ++i){
    if(firstPlot){
      if(log){ canv1->SetLogy(1); }
      // format x-axis
      std::string x_title;
      //x_title = std::string("#sigma#timesBR/#sigma#timesBR_{SM}");
      x_title = std::string("m_{#tau#tau}");
      hshape2[i]->SetXTitle(x_title.c_str());
      hshape2[i]->GetXaxis()->SetTitleFont(62);
      hshape2[i]->GetXaxis()->SetLabelFont(62);
      hshape2[i]->GetXaxis()->SetTitleColor(1);
      hshape2[i]->GetXaxis()->SetTitleOffset(1.05);

      // format y-axis
      std::string y_title;
      y_title = std::string("arbitary numbers"); 
      hshape2[i]->SetYTitle(y_title.c_str());
      hshape2[i]->GetXaxis()->SetTitleFont(62);
      hshape2[i]->GetYaxis()->SetLabelFont(62);
      //hshape2[i]->GetYaxis()->SetTitleSize(0.05);
      hshape2[i]->GetYaxis()->SetTitleOffset(1.05);
      hshape2[i]->GetYaxis()->SetLabelSize(0.03);
      hshape2[i]->GetXaxis()->SetRangeUser(0,400);
      hshape2[i]->SetMaximum(maximum);
      hshape2[i]->SetMinimum(minimum);
      }  
    hshape2[i]->SetLineStyle(11.);
    hshape2[i]->SetLineWidth(3.); 
    hshape2[i]->SetLineColor(kRed); 
    hshape2[i]->SetMarkerStyle(20);
    hshape2[i]->SetMarkerSize(MARKER_SIZE);
    hshape2[i]->SetMarkerColor(kRed);
    if(i>0) hshape2[0]->Add(hshape2[i]);
    firstPlot=false;  
  }
  hshape2[0]->Scale(1/hshape2[0]->Integral());
  //hshape2[0]->SetMaximum(maximum);
  //hshape2[0]->SetMinimum(minimum);
  hshape2[0]->SetLineStyle(11.);
  hshape2[0]->SetLineWidth(3.); 
  hshape2[0]->SetLineColor(kRed); 
  hshape2[0]->SetMarkerStyle(20);
  hshape2[0]->SetMarkerSize(MARKER_SIZE);
  hshape2[0]->SetMarkerColor(kRed);
  hshape2[0]->Draw("PLsame");
  canv1->RedrawAxis();

  TLegend* leg0;
  /// setup the CMS Preliminary
  CMSPrelim(label, "", 0.15, 0.835);
  leg0 = new TLegend(0.45, 0.70, 0.90, 0.90); 
  leg0->SetBorderSize( 0 );
  leg0->SetFillStyle ( 1001 );
  leg0->SetFillColor (kWhite);
  leg0->SetHeader( std::string(category+" Shapes").c_str() );
  std::string shape1cmb;
  for(unsigned int i=0; i<shape1.size(); ++i){
    if (i==0) shape1cmb=shape1[i];
    else shape1cmb=shape1cmb+"+"+shape1[i];
  }
  std::string shape2cmb;
  for(unsigned int i=0; i<shape2.size(); ++i){    
    if (i==0) shape2cmb=shape2[i];
    else shape2cmb=shape2cmb+"+"+shape2[i];
  }
  leg0->AddEntry( hshape1[0] , std::string(shape1cmb).c_str(),  "PL" );
  leg0->AddEntry( hshape2[0] , std::string(shape2cmb).c_str(),  "PL" );
  leg0->Draw("same");
  
  canv1->Print(std::string("CompareShapes-Absolute_"+category).append(".png").c_str());
  canv1->Print(std::string("CompareShapes-Absolute_"+category).append(".pdf").c_str());
  canv1->Print(std::string("CompareShapes-Absolute_"+category).append(".eps").c_str());


  /* not really working atm
  /// do the drawing
  TCanvas* canv2 = new TCanvas("canv2", "Relative Comparison", 600, 600);
  canv2->cd();
  canv2->SetGridx(1);
  canv2->SetGridy(1);

  TH1F* relative = (TH1F*)hshape1[0]->Clone();
  //TH1F* relative = new TH1F();
  //relative->Add(hshape1[0]);
  for(unsigned i=0; i<hshape1[0]->GetXaxis()->GetNbins(); i++){
    double content1=hshape1[0]->GetBinContent(i+1);
    double content2=hshape2[0]->GetBinContent(i+1);
    double content=0;
    if(content1!=0){
      content=(content1-content2)/content1;
    }
    std::cout<<i<<" "<<content1<<" "<<content2<<" "<<content<<std::endl;
    relative->SetBinContent(i+1, content);
  }

  std::string x_title;
  //x_title = std::string("#sigma#timesBR/#sigma#timesBR_{SM}");
  x_title = std::string("m_{#tau#tau}");
  relative->SetXTitle(x_title.c_str());
  relative->GetXaxis()->SetTitleFont(62);
  relative->GetXaxis()->SetLabelFont(62);
  relative->GetXaxis()->SetTitleColor(1);
  relative->GetXaxis()->SetTitleOffset(1.05);

  // format y-axis
  std::string y_title;
  y_title = std::string("arbitary numbers"); 
  relative->SetYTitle(y_title.c_str());
  relative->GetXaxis()->SetTitleFont(62);
  relative->GetYaxis()->SetLabelFont(62);
  //relative->GetYaxis()->SetTitleSize(0.05);
  relative->GetYaxis()->SetTitleOffset(1.05);
  relative->GetYaxis()->SetLabelSize(0.03);
  relative->GetXaxis()->SetRangeUser(0,500);
  relative->SetMaximum(1);
  relative->SetMinimum(-1);
  
  relative->SetLineStyle(11.);
  relative->SetLineWidth(3.); 
  relative->SetLineColor(kBlack); 
  relative->SetMarkerStyle(20);
  relative->SetMarkerSize(MARKER_SIZE);
  relative->SetMarkerColor(kBlack);
  relative->Draw("PL");
  canv2->RedrawAxis();

  TLegend* leg1;
  /// setup the CMS Preliminary
  CMSPrelim(label, "", 0.15, 0.835);
  leg1 = new TLegend(0.45, 0.60, 0.90, 0.90); 
  leg1->SetBorderSize( 0 );
  leg1->SetFillStyle ( 1001 );
  leg1->SetFillColor (kWhite);
  leg1->SetHeader( std::string(category+" Shapes").c_str() );
  leg1->AddEntry( relative , std::string("Relative to shape1").c_str(),  "PL" );
  leg1->Draw("same");


  canv2->Print(std::string("CompareShapes-Relative").append(".png").c_str());
  canv2->Print(std::string("CompareShapes-Relative").append(".pdf").c_str());
  canv2->Print(std::string("CompareShapes-Relative").append(".eps").c_str());
*/
  return;
}
void comparePValues(const char* filename, const char* channelstr, bool expected, bool observed, double minimum=1e-8, double maximum=1., bool log=true, const char* label="CMS Preliminary,  H#rightarrow#tau#tau,  4.9 fb^{-1} at 7 TeV, 19.8 fb^{-1} at 8 TeV", double legx0=0.2, double legy0=0.2, double legx1=0.6, double legy1=0.4)
{
    SetStyle();

    std::map<std::string, unsigned int> colors;
    colors["0jet"       ] = kBlue;
    colors["1jet"       ] = kRed;
    colors["2jet"       ] = kMagenta;
    colors["vbf"        ] = kRed;
    colors["boost"      ] = kGreen;
    colors["btag"       ] = kRed;
    colors["nobtag"     ] = kBlue;
    colors["em"         ] = kBlue;
    colors["et"         ] = kRed;
    colors["mt"         ] = kGreen;
    colors["mm"         ] = kMagenta;
    colors["ee"         ] = kCyan;
    colors["tt"         ] = kMagenta+3;
    colors["vhtt"       ] = kCyan-6;
    colors["cmb"        ] = kBlack;
    colors["htt"        ] = kBlack;
    colors["ggH"        ] = kRed;
    colors["bbH"        ] = kBlue;
    colors["HIG-11-020" ] = kBlue+2;
    colors["HIG-11-029" ] = kRed+2;
    colors["HIG-12-018" ] = kBlue;
    colors["HIG-12-032" ] = kRed+2;
    colors["HIG-12-043" ] = kRed;
    colors["HIG-12-050" ] = kRed;

    std::cout << " *******************************************************************************************************\n"
              << " * Usage     : root -l                                                                                  \n"
              << " *             .x MitLimits/Higgs2Tau/macros/comparePValues.C+(file, chn, exp, obs, type, min, max, log)\n"
              << " *                                                                                                      \n"
              << " * Arguments :  + file     const char*      full path to the input file                                 \n"
              << " *              + chn      const char*      list of channels; choose between: 'cmb', 'htt', 'emu',      \n"
              << " *                                          'etau', 'mutau', 'mumu', 'vhtt', 'hgg', 'hww', 'ggH',       \n"
              << " *                                          'bbH', 'nomix[-200, +200]', 'mhmax[-400, -200, +200]'       \n"
              << " *                                          'mhmax[+400, +600, +800]', 'test-0...5', 'saeff', 'gluph'   \n"
              << " *                                          The list should be comma separated and may contain          \n"
              << " *                                          whitespaces                                                 \n"
              << " *              + exp       bool            compare expected limits                                     \n"
              << " *              + obs       bool            compare observed limits                                     \n"
              << " *              + type      const char*     type of plot; choose between 'sm-xsec', 'mssm-xsec' and     \n"
              << " *                                          'mssm-tanb'                                                 \n"
              << " *              + max       double          maximum of the plot (default is 20.)                        \n"
              << " *                                                                                                      \n"
              << " *              + min       double          minimum of the plot (default is  0.)                        \n"
              << " *                                                                                                      \n"
              << " *              + log       bool            set log scale yes or no (default is false)                  \n"
              << " *                                                                                                      \n"
              << " *******************************************************************************************************\n";

    /// open input file
    TFile* inputFile = new TFile(filename);
    if(inputFile->IsZombie()) {
        std::cout << "ERROR:: file: " << filename << " does not exist.\n";
    }

    /// prepare input parameters
    std::vector<std::string> channels;
    string2Vector(cleanupWhitespaces(channelstr), channels);

    /// prepare histograms
    std::vector<TGraph*> hobs, hexp;
    for(unsigned i=0; i<channels.size(); ++i) {
        if(observed) hobs.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/observed").c_str()));
        if(expected) hexp.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/expected").c_str()));
    }

    /// do the drawing
    TCanvas* canv1 = new TCanvas("canv1", "Limit Comparison", 600, 600);
    canv1->cd();
    canv1->SetGridx(1);
    canv1->SetGridy(1);

    bool firstPlot=true;
    for(unsigned int i=0; i<hexp.size(); ++i) {
        if(firstPlot) {
            if(log) {
                canv1->SetLogy(1);
            }
            hexp[i]->SetMaximum(maximum);
            hexp[i]->SetMinimum(minimum);

            // format x-axis
            std::string x_title;
            x_title = std::string("m_{H} [GeV]");
            hexp[i]->GetXaxis()->SetTitle(x_title.c_str());
            hexp[i]->GetXaxis()->SetLabelFont(62);
            hexp[i]->GetXaxis()->SetTitleFont(62);
            hexp[i]->GetXaxis()->SetTitleColor(1);
            hexp[i]->GetXaxis()->SetTitleOffset(1.05);
            hexp[i]->GetXaxis()->SetLimits(hexp[i]->GetX()[0]-.1, hexp[i]->GetX()[hexp[i]->GetN()-1]+.1);

            // format y-axis
            std::string y_title;
            y_title = std::string("Local p-Value");
            hexp[i]->GetYaxis()->SetTitle(y_title.c_str());
            hexp[i]->GetYaxis()->SetLabelFont(62);
            hexp[i]->GetYaxis()->SetTitleOffset(1.05);
            hexp[i]->GetYaxis()->SetLabelSize(0.03);
        }
        hexp[i]->SetLineStyle(11.);
        hexp[i]->SetLineWidth( 3.);
        hexp[i]->SetLineColor(colors.find(channels[i])->second);
        hexp[i]->SetMarkerStyle(20);
        hexp[i]->SetMarkerSize(MARKER_SIZE);
        hexp[i]->SetMarkerColor(colors.find(channels[i])->second);
        hexp[i]->Draw(firstPlot ? "APL" : "PLsame");
        firstPlot=false;
    }
    for(unsigned int i=0; i<hobs.size(); ++i) {
        if(firstPlot) {
            if(log) {
                canv1->SetLogy(1);
            }
            hobs[i]->SetMaximum(maximum);
            hobs[i]->SetMinimum(minimum);

            // format x-axis
            std::string x_title;
            x_title = std::string("m_{H} [GeV]");
            hobs[i]->GetXaxis()->SetTitle(x_title.c_str());
            hobs[i]->GetXaxis()->SetLabelFont(62);
            hobs[i]->GetXaxis()->SetTitleFont(62);
            hobs[i]->GetXaxis()->SetTitleColor(1);
            hobs[i]->GetXaxis()->SetTitleOffset(1.05);
            hobs[i]->GetXaxis()->SetLimits(hobs[i]->GetX()[0]-.1, hobs[i]->GetX()[hobs[i]->GetN()-1]+.1);
            // format y-axis
            std::string y_title;
            y_title = std::string("Local p-value");
            hobs[i]->GetYaxis()->SetTitle(y_title.c_str());
            hobs[i]->GetYaxis()->SetLabelFont(62);
            hobs[i]->GetYaxis()->SetTitleOffset(1.05);
            hobs[i]->GetYaxis()->SetLabelSize(0.03);
        }
        hobs[i]->SetLineStyle(11.);
        hobs[i]->SetLineWidth( 3.);
        hobs[i]->SetLineColor(colors.find(channels[i])->second);
        hobs[i]->SetMarkerStyle(20);
        hobs[i]->SetMarkerSize(MARKER_SIZE);
        hobs[i]->SetMarkerColor(colors.find(channels[i])->second);
        hobs[i]->Draw(firstPlot ? "APL" : "PLsame");
        firstPlot=false;
    }
    canv1->RedrawAxis();

    // create the unit line
    TGraph* unit = new TGraph();
    for(int idx=0; idx<hexp[0]->GetN(); ++idx) {
        unit->SetPoint(idx, hexp[0]->GetX()[idx], 1.);
    }
    // create sigma lines
    std::vector<TGraph*> sigmas;
    for(unsigned int isigma=0; isigma<5; ++isigma) {
        TGraph* sigma = new TGraph();
        for(int idx=0; idx<hexp[0]->GetN(); ++idx) {
            sigma->SetPoint(idx, hexp[0]->GetX()[idx], ROOT::Math::normal_cdf_c(isigma+1));
        }
        sigmas.push_back(sigma);
    }

    unit->SetLineColor(kBlue);
    unit->SetLineWidth(3.);
    unit->Draw("Lsame");

    for(std::vector<TGraph*>::const_iterator sigma = sigmas.begin(); sigma!=sigmas.end(); ++sigma) {
        (*sigma)->SetLineColor(kRed);
        (*sigma)->SetLineWidth(3.);
        (*sigma)->Draw("Lsame");
    }

    /// 5 sigma
    TPaveText * sigma5 = new TPaveText(0.96, 0.25, 1.00, 0.30, "NDC");
    sigma5->SetBorderSize(   0 );
    sigma5->SetFillStyle(    0 );
    sigma5->SetTextAlign(   12 );
    sigma5->SetTextSize ( 0.04 );
    sigma5->SetTextColor( kRed );
    sigma5->SetTextFont (   62 );
    sigma5->AddText("5#sigma");
    sigma5->Draw("same");

    /// 4 sigma
    TPaveText * sigma4 = new TPaveText(0.96, 0.45, 1.00, 0.50, "NDC");
    sigma4->SetBorderSize(   0 );
    sigma4->SetFillStyle(    0 );
    sigma4->SetTextAlign(   12 );
    sigma4->SetTextSize ( 0.04 );
    sigma4->SetTextColor( kRed );
    sigma4->SetTextFont (   62 );
    sigma4->AddText("4#sigma");
    sigma4->Draw("same");

    /// 3 sigma
    TPaveText * sigma3 = new TPaveText(0.96, 0.61, 1.00, 0.66, "NDC");
    sigma3->SetBorderSize(   0 );
    sigma3->SetFillStyle(    0 );
    sigma3->SetTextAlign(   12 );
    sigma3->SetTextSize ( 0.04 );
    sigma3->SetTextColor( kRed );
    sigma3->SetTextFont (   62 );
    sigma3->AddText("3#sigma");
    sigma3->Draw("same");

    /// 2 sigma
    TPaveText * sigma2 = new TPaveText(0.96, 0.73, 1.00, 0.78, "NDC");
    sigma2->SetBorderSize(   0 );
    sigma2->SetFillStyle(    0 );
    sigma2->SetTextAlign(   12 );
    sigma2->SetTextSize ( 0.04 );
    sigma2->SetTextColor( kRed );
    sigma2->SetTextFont (   62 );
    sigma2->AddText("2#sigma");
    sigma2->Draw("same");

    /// 1 sigma
    TPaveText * sigma1 = new TPaveText(0.96, 0.82, 1.00, 0.87, "NDC");
    sigma1->SetBorderSize(   0 );
    sigma1->SetFillStyle(    0 );
    sigma1->SetTextAlign(   12 );
    sigma1->SetTextSize ( 0.04 );
    sigma1->SetTextColor( kRed );
    sigma1->SetTextFont (   62 );
    sigma1->AddText("1#sigma");
    sigma1->Draw("same");

    CMSPrelim(label, "", 0.15, 0.835);

    TLegend* leg0 = new TLegend(legx0, legy0, legx1, legy1);
    leg0->SetTextSize(0.03);
    leg0->SetBorderSize( 0 );
    leg0->SetFillStyle ( 1001 );
    leg0->SetFillColor (kWhite);
    if(observed) {
        for(unsigned int i=0; i<hobs.size(); ++i) {
            leg0->AddEntry( hobs[i] , channel(channels[i]) ? legendEntry(channels[i]).c_str() : legendEntry(channels[i]).append("-Channel").c_str(),  "PL" );
        }
    }
    if(expected) {
        for(unsigned int i=0; i<hexp.size(); ++i) {
            leg0->AddEntry( hexp[i] , channel(channels[i]) ? legendEntry(channels[i]).c_str() : legendEntry(channels[i]).append("-Channel").c_str(),  "PL" );
        }
    }
    leg0->Draw("same");

    canv1->Print(std::string("singlePValues").append(expected ? "_expected" : "").append(observed ? "_observed.png" : ".png").c_str());
    canv1->Print(std::string("singlePValues").append(expected ? "_expected" : "").append(observed ? "_observed.pdf" : ".pdf").c_str());
    canv1->Print(std::string("singlePValues").append(expected ? "_expected" : "").append(observed ? "_observed.eps" : ".eps").c_str());
    return;
}
Beispiel #5
0
void blindData(const char* filename, const char* background_patterns="Fakes, EWK, ttbar, Ztt", const char* signal_patterns="ggH125, qqH125, VH125", const char* directory_patterns="*", bool armed=false, int rnd=-1, float signal_scale=1., const char* outputLabel="", unsigned int debug=1)
{
  /// prepare input parameters
  std::vector<std::string> signals;
  string2Vector(cleanupWhitespaces(signal_patterns), signals);
  std::vector<std::string> samples;
  string2Vector(cleanupWhitespaces(background_patterns), samples);
  samples.insert(samples.end(), signals.begin(), signals.end());

  // check if mssm or sm input file
  bool sm=true;
  if(std::string(filename).find("mssm") != std::string::npos){
    sm=false;
    std::cerr << "INFO  : MSSM File " << std::endl;
  }
  
  // in case data_obs is supposed to be written to an extra output file
  // open the file, otherwise the data_obs in the input file will be
  // overwritten
  string used_filename=string(filename);
  TFile* outputFile = 0; 
  if(!std::string(outputLabel).empty()){
    std::string out = std::string(used_filename); 
    if(std::string(outputLabel).find("MSSM") != std::string::npos){
      outputFile = new TFile((out.substr(0, out.rfind("."))+".root").c_str(), "update"); 
    }
    // make sure data_obs in correct file for MSSM injection is changed
    // this is the old file which is overwritten 
    else{
      outputFile = new TFile((out.substr(0, out.rfind("."))+"_"+outputLabel+".root").c_str(), "update"); 
    }
  }

  TKey* idir;
  TH1F* buffer = 0;
  TH1F* blind_data_obs = 0;
  TFile* file = new TFile(used_filename.c_str(), "update");
  TIter nextDirectory(file->GetListOfKeys());
  while((idir = (TKey*)nextDirectory())){
    if( idir->IsFolder() ){
      file->cd(); // make sure to start in directory head 
      if( debug>0 ){ std::cerr << "Found directory: " << idir->GetName() << std::endl; }
      // check if we want to muck w/ this directory. For the vhtt case, we 
      // have different background types in the same root file, so we have 
      // to run blindData twice.
      if (!inPatterns(std::string(idir->GetName()), directory_patterns)) {
        if( debug>0 ){ 
	  std::cerr << "WARNING: Skipping directory: " << idir->GetName() << std::endl;
	  std::cerr << "         No match found in pattern: " << directory_patterns << std::endl; 
	}
        continue;
      }
      if( file->GetDirectory(idir->GetName()) ){
	file->cd(idir->GetName()); // change to sub-directory
	buffer = (TH1F*)file->Get((std::string(idir->GetName())+"/data_obs").c_str());
	if(!buffer){
	  std::cout << "WARNING: Did not find histogram data_obs in directory: " << idir->GetName() << std::endl;
	  std::cout << "         Will skip directory: " << std::endl;
	  continue;
	}
        blind_data_obs = (TH1F*)buffer->Clone("data_obs"); 
	if(!samples.empty()){
	  blind_data_obs->Reset();
	  std::cout << "INFO  : Blinding datacads now." << std::endl;
	  for(std::vector<std::string>::const_iterator sample = samples.begin(); sample!=samples.end(); ++sample){
	    if( debug>0 ){ std::cerr << "Looking for histogram: " << (std::string(idir->GetName())+"/"+(*sample)) << std::endl; }
	    // add special treatment for et/mt ZLL,ZJ,ZL here. You can run the
	    // macro with ZLL, ZL, ZJ in the background samples. Those samples,
	    // which do not apply for one or the other event category are 
	    // skipped here.
	    if(sm==true){
	      if(std::string(idir->GetName()).find("vbf") != std::string::npos  && (*sample == std::string("ZL") || *sample == std::string("ZJ"))){
		continue;
	      }
	      else if(std::string(idir->GetName()).find("vbf") == std::string::npos  && *sample == std::string("ZLL")){
		continue;
	      }
	    }
	    else{
	      if(std::string(idir->GetName()).find("nobtag") == std::string::npos && (*sample == std::string("ZL") || *sample == std::string("ZJ"))){
	      continue;
	      }
	      else if(std::string(idir->GetName()).find("nobtag") != std::string::npos && *sample == std::string("ZLL")){
	      continue;
	      }  
	    }
	    buffer = (TH1F*)file->Get((std::string(idir->GetName())+"/"+(*sample)).c_str()); 
	    if (!buffer) {
	      std::cerr << "ERROR : Could not get histogram from: " << std::string(idir->GetName())+"/"+(*sample) << std::endl;
	      std::cerr << "        Histogram will be skipped   : " << std::string(idir->GetName())+"/"+(*sample) << std::endl;
	      continue;
	    }
	    if(inPatterns(*sample, signal_patterns)) {
	      if( debug>1 ){
		std::cerr << "INFO  : Scale signal sample " << *sample << " by scale " << signal_scale << std::endl;
	      }
	      buffer->Scale(signal_scale);
	    }
	    blind_data_obs->Add(buffer);
	    if (debug > 1){
	      std::cerr << "INFO  : Adding: " << buffer->GetName() << " -- " << buffer->Integral() << " --> New value: " << blind_data_obs->Integral() << std::endl;
	    }
	  }
	}
	else{
	  std::cout << "INFO  : Data are not blinded." << std::endl;
	}
	if(rnd>=0){
	  // randomize histogram; this will automatically have integer integral
	  std::cerr << "-- R A N D O M I Z I N G --" << std::endl;
	  randomize(blind_data_obs, rnd, debug);
	}
	else{
	  // use expected mean with signal injected
	  blind_data_obs->Scale(TMath::Nint(blind_data_obs->Integral())/blind_data_obs->Integral());
	  // adjust uncertaintie
	  adjustUncerts(blind_data_obs);
	}
	std::cout << "INFO  : New data_obs yield: " << idir->GetName() << "   " << TMath::Nint(blind_data_obs->Integral()) << std::endl;
	if(armed){
          if (debug > 1){
            std::cerr << "INFO  : Writing to file: " << blind_data_obs->GetName() << std::endl;
	  }
	  if(outputFile){
	    // write to a dedicated new file with name output in case output has been specified
	    // make sure data_obs in correct file for MSSM injection is changed
	    // this is the old file which is overwritten 
	    if(std::string(outputLabel).find("MSSM") != std::string::npos){
	      outputFile->cd(idir->GetName());
	      blind_data_obs->Write("data_obs", TObject::kOverwrite);
	    }
	    else{
	      outputFile->mkdir(idir->GetName()); outputFile->cd(idir->GetName());
	      blind_data_obs->Write("data_obs"); 
	    }
	  }
	  else{
	    // override old data_obs in the inputfile otherwise
	    file->cd(idir->GetName());
	    blind_data_obs->Write("data_obs", TObject::kOverwrite); 
	  }
	}
      }
    }
  }
  file->Close();
  if(outputFile){
    outputFile->Close();
  }
  return;
}
void compareLimits(const char* filename, const char* channelstr, bool expected, bool observed, const char* type, double minimum=0., double maximum=20., bool log=false, const char* label="#scale[1.5]{CMS}   h,H,A#rightarrow#tau#tau                     19.7 fb^{-1} (8 TeV) + 4.9 fb^{-1} (7 TeV)", bool legendOnRight=true, bool legendOnTop=true, bool ggH=true)
{
  SetStyle();

  std::map<std::string, unsigned int> colors;
  colors["0jet"       ] = kBlue;
  colors["1jet"       ] = kRed;
  colors["2jet"       ] = kMagenta;
  colors["vbf"        ] = kMagenta;
  colors["boost"      ] = kGreen;
  colors["btag"       ] = kRed; 
  colors["nobtag"     ] = kBlue; 
  colors["em"         ] = kBlue;
  colors["et"         ] = kRed;
  colors["mt"         ] = kGreen;
  colors["mm"         ] = kMagenta;
  colors["ee"         ] = kCyan;
  colors["tt"         ] = kMagenta+3;
  colors["vhtt"       ] = kCyan-6;
  colors["cmb"        ] = kBlack;
  colors["htt"        ] = kBlack;
  colors["ggH"        ] = kRed;
  colors["bbH"        ] = kBlue;
  colors["HIG-11-020" ] = kBlue+2;
  colors["HIG-11-029" ] = kRed+2;
  colors["HIG-12-018" ] = kBlue;
  colors["HIG-12-032" ] = kRed+2;
  colors["HIG-12-043" ] = kRed;
  colors["HIG-12-050" ] = kRed;

  std::cout << " *******************************************************************************************************\n"
	    << " * Usage     : root -l                                                                                  \n"
	    << " *             .x MitLimits/Higgs2Tau/macros/compareLimits.C+(file, chn, exp, obs, type, min, max, log) \n"
	    << " *                                                                                                      \n"
	    << " * Arguments :  + file     const char*      full path to the input file                                 \n"
	    << " *              + chn      const char*      list of channels; choose between: 'cmb', 'htt', 'emu',      \n"
	    << " *                                          'etau', 'mutau', 'mumu', 'vhtt', 'hgg', 'hww', 'ggH',       \n"
	    << " *                                          'bbH', 'nomix[-200, +200]', 'mhmax[-400, -200, +200]'       \n"
	    << " *                                          'mhmax[+400, +600, +800]', 'test-0...5', 'saeff', 'gluph'   \n"
	    << " *                                          The list should be comma separated and may contain          \n"
	    << " *                                          whitespaces                                                 \n"
	    << " *              + exp       bool            compare expected limits                                     \n"
	    << " *              + obs       bool            compare observed limits                                     \n"
	    << " *              + type      const char*     type of plot; choose between 'sm-xsec', 'mssm-xsec' and     \n"
	    << " *                                          'mssm-tanb'                                                 \n"
	    << " *              + max       double          maximum of the plot (default is 20.)                        \n"
	    << " *                                                                                                      \n"
	    << " *              + min       double          minimum of the plot (default is  0.)                        \n"
	    << " *                                                                                                      \n"
	    << " *              + log       bool            set log scale yes or no (default is false)                  \n"
	    << " *                                                                                                      \n"
	    << " *******************************************************************************************************\n";

  /// open input file  
  TFile* inputFile = new TFile(filename); if(inputFile->IsZombie()){ std::cout << "ERROR:: file: " << filename << " does not exist.\n"; }
  
  /// prepare input parameters
  std::vector<std::string> channels;
  string2Vector(cleanupWhitespaces(channelstr), channels);

  /// prepare histograms
  std::vector<TGraph*> hobs, hexp;
  for(unsigned i=0; i<channels.size(); ++i){
    if(observed) hobs.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/observed").c_str()));
    if(expected) hexp.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/expected").c_str()));
  }

  /// do the drawing
  TCanvas* canv1 = new TCanvas("canv1", "Limit Comparison", 600, 600);
  canv1->cd();
  canv1->SetGridx(1);
  canv1->SetGridy(1);
  if((std::string(type) == std::string("mssm-xsec") || std::string(type) == std::string("mssm-tanb")) && log) canv1->SetLogx(1); 

  bool firstPlot=true;
  for(unsigned int i=0; i<hexp.size(); ++i){
    if(firstPlot){
	if(log){ canv1->SetLogy(1); }
	hexp[i]->SetMaximum(maximum);
	hexp[i]->SetMinimum(minimum);
      
      // format x-axis
      std::string x_title;
      if(std::string(type) == std::string("mssm-tanb")){
	x_title = std::string("m_{A} [GeV]");
      }
      else if(std::string(type) == std::string("mssm-xsec")){
	x_title = std::string("m_{#phi} [GeV]");
      }
      else{
	x_title = std::string("m_{H} [GeV]");
      }
      hexp[i]->GetXaxis()->SetTitle(x_title.c_str());
      hexp[i]->GetXaxis()->SetLabelFont(62);
      hexp[i]->GetXaxis()->SetTitleFont(62);
      hexp[i]->GetXaxis()->SetTitleColor(1);
      hexp[i]->GetXaxis()->SetTitleOffset(1.05);
      if((std::string(type) == std::string("mssm-xsec") || std::string(type) == std::string("mssm-tanb")) && log){
	hexp[i]->GetXaxis()->SetNdivisions(50005, "X");
	hexp[i]->GetXaxis()->SetMoreLogLabels();
	hexp[i]->GetXaxis()->SetNoExponent();
	hexp[i]->GetXaxis()->SetLabelSize(0.040);
      }
      hexp[i]->GetXaxis()->SetLimits(hexp[i]->GetX()[0]-.1, hexp[i]->GetX()[hexp[i]->GetN()-1]+.1);
      if(std::string(type) == std::string("mssm-xsec") || std::string(type) == std::string("mssm-tanb")){
	if(log){
	  hexp[i]->GetXaxis()->SetLimits(hexp[i]->GetX()[0], hexp[i]->GetX()[hexp[i]->GetN()-1]+.1);
	}
	else{
	  hexp[i]->GetXaxis()->SetLimits(hexp[i]->GetX()[0]-.1, hexp[i]->GetX()[hexp[i]->GetN()-1]+.1);
	}      
      }

      // format y-axis
      std::string y_title;
      if( std::string(type) == std::string("mssm-xsec") ){
	if(ggH) y_title = std::string("95% CL limit on #sigma(gg#rightarrow#phi)#timesBR [pb]");
	else y_title = std::string("95% CL limit on #sigma(gg#rightarrowbb#phi)#timesBR [pb]");
      }
      else if(  std::string(type) == std::string("mssm-tanb")  ){
	y_title = std::string("#bf{tan#beta}");
      }
      else{
	y_title = std::string("95% CL limit on #sigma/#sigma_{SM}");
      }
      hexp[i]->GetYaxis()->SetTitle(y_title.c_str());
      hexp[i]->GetYaxis()->SetLabelFont(62);
      hexp[i]->GetYaxis()->SetTitleFont(62);
      hexp[i]->GetYaxis()->SetTitleOffset(1.05);
      hexp[i]->GetYaxis()->SetLabelSize(0.03);
    }
    hexp[i]->SetLineStyle(11.);
    hexp[i]->SetLineWidth( 3.); 
    hexp[i]->SetLineColor(colors.find(channels[i])->second);
    hexp[i]->SetMarkerStyle(20);
    hexp[i]->SetMarkerSize(MARKER_SIZE);
    hexp[i]->SetMarkerColor(colors.find(channels[i])->second);
    hexp[i]->Draw(firstPlot ? "APL" : "PLsame");
    //hexp[i]->Draw(firstPlot ? "AL" : "Lsame");
    firstPlot=false;
  }
  for(unsigned int i=0; i<hobs.size(); ++i){
    if(firstPlot){
      if(log){ canv1->SetLogy(1); }
      hobs[i]->SetMaximum(maximum);
      hobs[i]->SetMinimum(minimum);
      
      // format x-axis
      std::string x_title;
      if(std::string(type) == std::string("mssm-tanb")){
	x_title = std::string("m_{A} [GeV]");
      }
      else if(std::string(type) == std::string("mssm-xsec")){
	x_title = std::string("m_{#phi} [GeV]");
      }
      else{
	x_title = std::string("m_{H} [GeV]");
      }
      hobs[i]->GetXaxis()->SetTitle(x_title.c_str());
      hobs[i]->GetXaxis()->SetLabelFont(62);
      hobs[i]->GetXaxis()->SetTitleFont(62);
      hobs[i]->GetXaxis()->SetTitleColor(1);
      hobs[i]->GetXaxis()->SetTitleOffset(1.05);
      if((std::string(type) == std::string("mssm-xsec") || std::string(type) == std::string("mssm-tanb")) && log){
	hobs[i]->GetXaxis()->SetNdivisions(50005, "X");
	hobs[i]->GetXaxis()->SetMoreLogLabels();
	hobs[i]->GetXaxis()->SetNoExponent();
	hobs[i]->GetXaxis()->SetLabelSize(0.040);
      }
      hobs[i]->GetXaxis()->SetLimits(hobs[i]->GetX()[0]-.1, hobs[i]->GetX()[hobs[i]->GetN()-1]+.1);
      if(std::string(type) == std::string("mssm-xsec") || std::string(type) == std::string("mssm-tanb")){
	if(log){
	  hobs[i]->GetXaxis()->SetLimits(hobs[i]->GetX()[0], hobs[i]->GetX()[hobs[i]->GetN()-1]+.1);
	}
	else{
	  hobs[i]->GetXaxis()->SetLimits(hobs[i]->GetX()[0]-.1, hobs[i]->GetX()[hobs[i]->GetN()-1]+.1);
	}      
      }
      
      // format y-axis
      std::string y_title;
      if( std::string(type) == std::string("mssm-xsec") ){
	if(ggH) y_title = std::string("95% CL limit on #sigma#font[42]{(gg#phi)}#upoint#font[52]{B}#font[42]{(#phi#rightarrow#tau#tau)} [pb]");
	else y_title = std::string("95% CL limit on #sigma#font[42]{(bb#phi)}#upoint#font[52]{B}#font[42]{(#phi#rightarrow#tau#tau)} [pb]");
      }
      else if(  std::string(type) == std::string("mssm-tanb")  ){
	y_title = std::string("#bf{tan#beta}");
      }
      else{
	y_title = std::string("95% CL limit on #sigma/#sigma_{SM}");
      }
      hobs[i]->GetYaxis()->SetTitle(y_title.c_str());
      hobs[i]->GetYaxis()->SetLabelFont(62);
      hobs[i]->GetYaxis()->SetTitleOffset(1.05);
      hobs[i]->GetYaxis()->SetLabelSize(0.03);
    }
    hobs[i]->SetLineStyle(11.);
    hobs[i]->SetLineWidth( 3.); 
    hobs[i]->SetLineColor(colors.find(channels[i])->second);
    hobs[i]->SetMarkerStyle(20);
    hobs[i]->SetMarkerSize(MARKER_SIZE);
    hobs[i]->SetMarkerColor(colors.find(channels[i])->second);
    hobs[i]->Draw(firstPlot ? "APL" : "PLsame");
    //hobs[i]->Draw(firstPlot ? "AL" : "Lsame");
    firstPlot=false;
  }
  canv1->RedrawAxis();

  TPaveText* extra;
  if( std::string(type) == std::string("mssm-xsec") ){
    extra = new TPaveText(legendOnRight ? 0.6 : 0.18, 0.50, legendOnRight ? 0.95 : 0.605, 0.60, "NDC");
    extra->SetBorderSize(   0 );
    extra->SetFillStyle (   0 );
    extra->SetTextAlign (  12 );
    extra->SetTextSize  (0.04 );
    extra->SetTextColor (   1 );
    extra->SetTextFont  (  62 );
    if(ggH) extra->AddText("gg#phi");
    else extra->AddText("bb#phi");
    extra->Draw();
  }

  bool firstLeg=true;
  if(observed){
    TLegend* leg1;
    if(expected && observed){
      /// setup the CMS Preliminary
       if(std::string(type) == std::string("mssm-tanb")){
	  if (firstLeg) CMSPrelim(label, "", 0.15, 0.835);
	  leg1 = new TLegend(firstLeg ? 0.60 : 0.20, hobs.size()<5 ? 0.20-0.06*hobs.size() : 0.4, firstLeg ? 0.93 : 0.60, 0.20);
       }
       else{
	  if (firstLeg) CMSPrelim(label, "", 0.135, 0.835);
	  leg1 = new TLegend(firstLeg ? 0.20 : 0.20, hobs.size()<5 ? 0.90-0.08*hobs.size() : 0.6, firstLeg ? 0.63 : 0.60, 0.90);
       }
    }
    else{
      /// setup the CMS Preliminary
      if(std::string(type) == std::string("mssm-tanb")){
	CMSPrelim(label, "", 0.15, 0.835);
	leg1 = new TLegend(legendOnRight?0.60:0.20, hobs.size()<5 ? (legendOnTop?0.90:0.40)-0.04*hobs.size() : (legendOnTop?0.6:0.2), legendOnRight?0.94:0.45, (legendOnTop?0.90:0.40));
	   }
      else{
	CMSPrelim(label, "", 0.135, 0.835);
	leg1 = new TLegend(legendOnRight ? 0.50 : 0.20, hobs.size()<5 ? 0.90-0.08*hobs.size() : 0.6, legendOnRight ? 0.94 : 0.64, 0.90);
      }
    }
    if(std::string(type) == std::string("mssm-tanb")) {leg1->SetTextSize(0.03);}
    //leg1->SetTextSize(0.02);
    leg1->SetBorderSize( 0 );
    leg1->SetFillStyle ( 1001 );
    //leg1->SetFillColor ( 0 );
    leg1->SetFillColor (kWhite);
    leg1->SetHeader( "#bf{observed}" );
    for(unsigned int i=0; i<hobs.size(); ++i){
      leg1->AddEntry( hobs[i] , channel(channels[i]) ? legendEntry(channels[i]).c_str() : legendEntry(channels[i]).append("-Channel").c_str(),  "PL" );
    }
    leg1->Draw("same");
    firstLeg=false;
  }
  if(expected){
    TLegend* leg0;
    if(expected && observed){
      /// setup the CMS Preliminary
      if(std::string(type) == std::string("mssm-tanb")){
	CMSPrelim(label, "", 0.15, 0.835);
	leg0 = new TLegend(legendOnRight ? 0.60 : 0.20, hexp.size()<5 ? 0.20-0.06*hexp.size() : 0.4, legendOnRight ? 0.94 : 0.63, 0.20);
      }
      else{
	CMSPrelim(label, "", 0.135, 0.835);
	leg0 = new TLegend(legendOnRight ? 0.20 : 0.20, hexp.size()<5 ? 0.75-0.08*hexp.size() : 0.6, legendOnRight ? 0.94 : 0.63, 0.75);
      }
    }
    else{
      /// setup the CMS Preliminary
      if(std::string(type) == std::string("mssm-tanb")){
	CMSPrelim(label, "", 0.15, 0.835);
	leg0 = new TLegend(legendOnRight?0.60:0.20, hexp.size()<5 ? (legendOnTop?0.90:0.40)-0.04*hexp.size() : (legendOnTop?0.6:0.2), legendOnRight?0.94:0.45, (legendOnTop?0.90:0.40));
	   }
      else{
	CMSPrelim(label, "", 0.135, 0.835);
	leg0 = new TLegend(legendOnRight ? 0.50 : 0.20, hexp.size()<5 ? 0.90-0.06*hexp.size() : 0.6, legendOnRight ? 0.74 : 0.63, 0.90);
	//leg0 = new TLegend(legendOnRight ? 0.50 : 0.20, hexp.size()<5 ? 0.90-0.08*hexp.size() : 0.6, legendOnRight ? 0.94 : 0.80, 0.90);
      }
    }
    if(std::string(type) == std::string("mssm-tanb")) {leg0->SetTextSize(0.03);}
    leg0->SetBorderSize( 0 );
    leg0->SetFillStyle ( 1001 );
    leg0->SetFillColor (kWhite);
    leg0->SetHeader( "#bf{expected}" );
    for(unsigned int i=0; i<hexp.size(); ++i){
      leg0->AddEntry( hexp[i] , channel(channels[i]) ? legendEntry(channels[i]).c_str() : legendEntry(channels[i]).append("-Channel").c_str(),  "PL" );
    }
    leg0->Draw("same");
    firstLeg=false;
  }
  canv1->Print(std::string("singleLimits").append(expected ? "_expected" : "").append(observed ? "_observed" : "").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.png" : "_sm.png").c_str());
  canv1->Print(std::string("singleLimits").append(expected ? "_expected" : "").append(observed ? "_observed" : "").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.pdf" : "_sm.pdf").c_str());
  canv1->Print(std::string("singleLimits").append(expected ? "_expected" : "").append(observed ? "_observed" : "").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.pdf" : "_sm.eps").c_str());
  return;
}
void compareLimits(const char* filename, const char* channelstr, bool expected, bool observed, const char* type, double minimum=0., double maximum=20., bool log=false, const char* label=" Preliminary, #sqrt{s} = 7+8 TeV, H#rightarrow#tau#tau, L = 10 fb^{-1}", bool legendOnRight = true)
{
  SetStyle();

  std::map<std::string, unsigned int> colors;
  colors["incl"      ] = kBlue;
  colors["0jet"      ] = kBlue;
  colors["2jet"      ] = kMagenta;
  colors["vbf"       ] = kRed;
  colors["boost"     ] = kGreen;
  colors["emu"       ] = kBlue;
  colors["em"        ] = kBlue;
  colors["etau"      ] = kRed;
  colors["et"        ] = kRed;
  colors["mutau"     ] = kGreen;
  colors["mt"        ] = kGreen;
  colors["mumu"      ] = kMagenta;
  colors["mm"        ] = kMagenta;
  colors["tautau"    ] = kOrange;
  colors["tt"        ] = kOrange;
  colors["vhtt"      ] = kMagenta+2;
  colors["whtt"      ] = kMagenta+0;
  colors["zhtt"      ] = kCyan+2;
  colors["whhh"      ] = kBlue;
  colors["cmb"       ] = kBlack;
  colors["htt"       ] = kBlack;
  colors["htt+"      ] = kBlue;
  colors["hgg"       ] = kRed;
  colors["hww"       ] = kGreen;
  colors["4l"        ] = kGreen;
  colors["llt"       ] = kRed;
  colors["ltt"       ] = kBlue;
  colors["hzz4l"     ] = kBlue;
  colors["hzz2l2q"   ] = kMagenta;
  colors["hzz2l2q+"  ] = kMagenta;
  colors["hzz2l2t"   ] = kOrange;
  colors["hzz2l2n"   ] = kPink;
  colors["ggH"       ] = kRed;
  colors["bbH"       ] = kBlue;
  colors["test-0"    ] = kBlue+2;
  colors["test-1"    ] = kRed+2;
  colors["test-2"    ] = kGreen;
  colors["test-3"    ] = kRed+2;
  colors["test-4"    ] = kBlue;
  colors["test-5"    ] = kViolet-6;
  colors["cmb-5fb"   ] = kBlue;
  colors["hpa-5fb"   ] = kRed;
  colors["hpa-10fb"  ] = kBlack;
  colors["saeff"     ] = kGreen;
  colors["gluph"     ] = kOrange-3;
  colors["nomix-200" ] = kBlue-10;
  colors["nomix+200" ] = kBlue +2;
  colors["mhmax-400" ] = kGray +2;
  colors["mhmax-200" ] = kGray +1;
  colors["mhmax+200" ] = kMagenta+ 4;
  colors["mhmax+400" ] = kMagenta+ 3;
  colors["mhmax+600" ] = kMagenta- 2;
  colors["mhmax+800" ] = kMagenta-10;
  colors["HIG-11-020"] = kBlue+2;
  colors["HIG-11-029"] = kRed+2;
  colors["HIG-12-018"] = kBlue;
  colors["HIG-12-032"] = kRed+2;

  std::cout << " *******************************************************************************************************\n"
	    << " * Usage     : root -l                                                                                  \n"
	    << " *             .x MitLimits/Higgs2Tau/macros/compareLimits.C+(file, chn, exp, obs, type, min, max, log) \n"
	    << " *                                                                                                      \n"
	    << " * Arguments :  + file     const char*      full path to the input file                                 \n"
	    << " *              + chn      const char*      list of channels; choose between: 'cmb', 'htt', 'emu',      \n"
	    << " *                                          'etau', 'mutau', 'mumu', 'vhtt', 'hgg', 'hww', 'ggH',       \n"
	    << " *                                          'bbH', 'nomix[-200, +200]', 'mhmax[-400, -200, +200]'       \n"
	    << " *                                          'mhmax[+400, +600, +800]', 'test-0...5', 'saeff', 'gluph'   \n"
	    << " *                                          The list should be comma separated and may contain          \n"
	    << " *                                          whitespaces                                                 \n"
	    << " *              + exp       bool            compare expected limits                                     \n"
	    << " *              + obs       bool            compare observed limits                                     \n"
	    << " *              + type      const char*     type of plot; choose between 'sm-xsec', 'mssm-xsec' and     \n"
	    << " *                                          'mssm-tanb'                                                 \n"
	    << " *              + max       double          maximum of the plot (default is 20.)                        \n"
	    << " *                                                                                                      \n"
	    << " *              + min       double          minimum of the plot (default is  0.)                        \n"
	    << " *                                                                                                      \n"
	    << " *              + log       bool            set log scale yes or no (default is false)                  \n"
	    << " *                                                                                                      \n"
	    << " *******************************************************************************************************\n";

  /// open input file  
  TFile* inputFile = new TFile(filename); if(inputFile->IsZombie()){ std::cout << "ERROR:: file: " << filename << " does not exist.\n"; }

  /// prepare input parameters
  std::vector<std::string> channels;
  string2Vector(cleanupWhitespaces(channelstr), channels);

  /// prepare histograms
  std::vector<TGraph*> hobs, hexp;
  for(unsigned i=0; i<channels.size(); ++i){
    if(observed) hobs.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/observed").c_str()));
    if(expected) hexp.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/expected").c_str()));
  }

  /// do the drawing
  TCanvas* canv1 = new TCanvas("canv1", "Limit Comparison", 600, 600);
  canv1->cd();
  canv1->SetGridx(1);
  canv1->SetGridy(1);
 
  bool firstPlot=true;
  for(unsigned int i=0; i<hexp.size(); ++i){
    if(firstPlot){
      if(std::string(type) == std::string("mssm-xsec")){
	if(log){ canv1->SetLogy(1); }
	hexp[i]->SetMaximum(maximum);
	hexp[i]->SetMinimum(minimum);
      }
      else{
	if(log){ canv1->SetLogy(1); }
	hexp[i]->SetMaximum(maximum);
	hexp[i]->SetMinimum(minimum);
      }
      
      // format x-axis
      std::string x_title;
      if(std::string(type).find("mssm")!=std::string::npos){
	x_title = std::string("m_{A} [GeV]");
      }
      else{
	x_title = std::string("m_{H} [GeV]");
      }
      hexp[i]->GetXaxis()->SetTitle(x_title.c_str());
      hexp[i]->GetXaxis()->SetLabelFont(62);
      hexp[i]->GetXaxis()->SetTitleFont(62);
      hexp[i]->GetXaxis()->SetTitleColor(1);
      hexp[i]->GetXaxis()->SetTitleOffset(1.05);
      
      // format y-axis
      std::string y_title;
      if( std::string(type) == std::string("mssm-xsec") ){
	y_title = std::string("#sigma(#phi#rightarrow#tau#tau)_{95% CL} [pb]");
      }
      else if(  std::string(type) == std::string("mssm-tanb")  ){
	y_title = std::string("#bf{tan#beta}");
      }
      else{
	//y_title = std::string("#sigma(H#rightarrow#tau#tau)_{95% CL} / #sigma(H#rightarrow#tau#tau)_{SM}");
	y_title = std::string("95% CL limit on #sigma/#sigma_{SM}");
      }
      hexp[i]->GetYaxis()->SetTitle(y_title.c_str());
      hexp[i]->GetYaxis()->SetLabelFont(62);
      hexp[i]->GetYaxis()->SetTitleOffset(1.05);
      hexp[i]->GetYaxis()->SetLabelSize(0.03);
      hexp[i]->GetXaxis()->SetLimits(hexp[i]->GetX()[0]-.1, hexp[i]->GetX()[hexp[i]->GetN()-1]+.1);
    }
    hexp[i]->SetLineStyle(11.);
    hexp[i]->SetLineWidth( 3.); 
    hexp[i]->SetLineColor(colors.find(channels[i])->second);
    hexp[i]->SetMarkerStyle(20);
    hexp[i]->SetMarkerSize(MARKER_SIZE);
    hexp[i]->SetMarkerColor(colors.find(channels[i])->second);
    hexp[i]->Draw(firstPlot ? "APL" : "PLsame");
    //hexp[i]->Draw(firstPlot ? "AL" : "Lsame");
    firstPlot=false;
  }
  for(unsigned int i=0; i<hobs.size(); ++i){
    if(firstPlot){
      if(std::string(type) == std::string("mssm-xsec")){
	if(log){ canv1->SetLogy(1); }
	hobs[i]->SetMaximum(maximum);
	hobs[i]->SetMinimum(minimum);
      }
      else{
	if(log){ canv1->SetLogy(1); }
	hobs[i]->SetMaximum(maximum);
	hobs[i]->SetMinimum(minimum);
      }
      
      // format x-axis
      std::string x_title;
      if(std::string(type).find("mssm")!=std::string::npos){
	x_title = std::string("m_{A} [GeV]");
      }
      else{
	x_title = std::string("m_{H} [GeV]");
      }
      hobs[i]->GetXaxis()->SetTitle(x_title.c_str());
      hobs[i]->GetXaxis()->SetLabelFont(62);
      hobs[i]->GetXaxis()->SetTitleFont(62);
      hobs[i]->GetXaxis()->SetTitleColor(1);
      hobs[i]->GetXaxis()->SetTitleOffset(1.05);
      
      // format y-axis
      std::string y_title;
      if( std::string(type) == std::string("mssm-xsec") ){
	y_title = std::string("#sigma(#phi#rightarrow#tau#tau)_{95% CL} [pb]");
      }
      else if(  std::string(type) == std::string("mssm-tanb")  ){
	y_title = std::string("#bf{tan#beta}");
      }
      else{
	//y_title = std::string("#sigma(H#rightarrow#tau#tau)_{95% CL} / #sigma(H#rightarrow#tau#tau)_{SM}");
	y_title = std::string("#sigma(H)_{95% CL} / #sigma(H)_{SM}");
      }
      hobs[i]->GetYaxis()->SetTitle(y_title.c_str());
      hobs[i]->GetYaxis()->SetLabelFont(62);
      hobs[i]->GetYaxis()->SetTitleOffset(1.05);
      hobs[i]->GetYaxis()->SetLabelSize(0.03);
      hobs[i]->GetXaxis()->SetLimits(hobs[i]->GetX()[0]-.1, hobs[i]->GetX()[hobs[i]->GetN()-1]+.1);
    }
    hobs[i]->SetLineWidth( 3.); 
    hobs[i]->SetLineColor(colors.find(channels[i])->second);
    hobs[i]->SetMarkerStyle(20);
    hobs[i]->SetMarkerSize(MARKER_SIZE);
    hobs[i]->SetMarkerColor(colors.find(channels[i])->second);
    hobs[i]->Draw(firstPlot ? "APL" : "PLsame");
    //hobs[i]->Draw(firstPlot ? "AL" : "Lsame");
    firstPlot=false;
  }
  canv1->RedrawAxis();

  bool firstLeg=true;
  if(observed){
    TLegend* leg1;
    if(expected && observed){
      /// setup the CMS Preliminary
      if (firstLeg) CMSPrelim(label, "", 0.15, 0.835);
      leg1 = new TLegend(firstLeg ? 0.60 : 0.20, hobs.size()<5 ? 0.90-0.06*hobs.size() : 0.6, firstLeg ? 0.93 : 0.60, 0.90);
    }
    else{
      /// setup the CMS Preliminary
      CMSPrelim(label, "", 0.15, 0.835);
      leg1 = new TLegend(legendOnRight ? 0.50 : 0.20, hobs.size()<5 ? 0.90-0.06*hobs.size() : 0.6, legendOnRight ? 0.93 : 0.63, 0.90);
    }
    leg1->SetBorderSize( 0 );
    leg1->SetFillStyle ( 0 );
    leg1->SetFillColor ( 0 );
    leg1->SetFillColor (kWhite);
    leg1->SetHeader( "#bf{Observed Limit}" );
    for(unsigned int i=0; i<hobs.size(); ++i){
      // skip one of the two split options
      if(channels[i] == std::string("hzz2l2q+")){ continue; }
      leg1->AddEntry( hobs[i] , channel(channels[i]) ? legendEntry(channels[i]).c_str() : legendEntry(channels[i]).append("-Channel").c_str(),  "PL" );
    }
    leg1->Draw("same");
    firstLeg=false;
  }
  if(expected){
    TLegend* leg0;
    if(expected && observed){
      /// setup the CMS Preliminary
      if (firstLeg) CMSPrelim(label, "", 0.15, 0.835);
      leg0 = new TLegend(firstLeg ? 0.60 : 0.20, hexp.size()<5 ? 0.90-0.06*hexp.size() : 0.8, firstLeg ? 0.94 : 0.60, 0.90);
    }
    else{
      /// setup the CMS Preliminary
      CMSPrelim(label, "", 0.15, 0.835);
      leg0 = new TLegend(legendOnRight ? 0.50 : 0.20, hexp.size()<5 ? 0.90-0.06*hexp.size() : 0.6, legendOnRight ? 0.94 : 0.64, 0.90);
    }
    leg0->SetBorderSize( 0 );
    leg0->SetFillStyle ( 0 );
    leg0->SetFillColor (kWhite);
    leg0->SetHeader( "#bf{Expected Limit}" );
    for(unsigned int i=0; i<hexp.size(); ++i){
      // skip one of the two split options
      if(channels[i] == std::string("hzz2l2q+")){ continue; }
      leg0->AddEntry( hexp[i] , channel(channels[i]) ? legendEntry(channels[i]).c_str() : legendEntry(channels[i]).append("-Channel").c_str(),  "PL" );
    }
    leg0->Draw("same");
    firstLeg=false;
  }
  canv1->Print(std::string("singleLimits").append(expected ? "_expected" : "").append(observed ? "_observed" : "").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.png" : "_sm.png").c_str());
  canv1->Print(std::string("singleLimits").append(expected ? "_expected" : "").append(observed ? "_observed" : "").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.pdf" : "_sm.pdf").c_str());
  canv1->Print(std::string("singleLimits").append(expected ? "_expected" : "").append(observed ? "_observed" : "").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.pdf" : "_sm.eps").c_str());
  return;
}
void asymptoticLimit(const char* outputfile, const char* inputfiles, unsigned int verbosity=2, bool upper_exclusion=true)
{
  // prepare input names from inputfiles
  std::vector<std::string> tanb_files;
  string2Vector(cleanupWhitespaces(inputfiles), tanb_files);
  // prepare tanb values from inputfiles
  std::map<double, std::string> tanb_values;  
  for(std::vector<std::string>::const_iterator tanb_file = tanb_files.begin(); tanb_file!=tanb_files.end(); ++tanb_file){
    tanb_values[atof(tanb_file->substr(tanb_file->rfind("_")+1, tanb_file->find(".root")-tanb_file->rfind("_")-1).c_str())] = *tanb_file;
  }
  
  double limit, lowlimit;
  TGraph* graph = new TGraph();
  TFile* file = TFile::Open(outputfile, "update");
  TTree* tree = new TTree("limit", "limit");
  tree->Branch("limit", &limit, "limit/D");
  tree->Branch("lowlimit", &lowlimit, "lowlimit/D");
  for(unsigned int itype=0; itype<all_types; ++itype){
    graph->Clear();
    if( std::string(outputfile).find("quant0.027")!=std::string::npos ){
      if( itype == minus_2sigma ){
	fillTree(tree, graph, limit, lowlimit, itype, tanb_values, upper_exclusion, verbosity);
	break;
      }
    }
    else if( std::string(outputfile).find("quant0.160")!=std::string::npos ){
      if( itype == minus_1sigma ){
	fillTree(tree, graph, limit, lowlimit, itype, tanb_values, upper_exclusion, verbosity);
	break;
      }
    }
    else if( std::string(outputfile).find("quant0.500")!=std::string::npos ){
      if( itype == expected ){
	fillTree(tree, graph, limit, lowlimit, itype, tanb_values, upper_exclusion, verbosity);
	break;
      }
    }
    else if( std::string(outputfile).find("quant0.840")!=std::string::npos ){
      if( itype == plus_1sigma ){
	fillTree(tree, graph, limit, lowlimit, itype, tanb_values, upper_exclusion, verbosity);
	break;
      }
    }
    else if( std::string(outputfile).find("quant0.975")!=std::string::npos ){
      if( itype == plus_2sigma ){
	fillTree(tree, graph, limit, lowlimit, itype, tanb_values, upper_exclusion, verbosity);
	break;
      }
    }
    else{
      if( itype == observed ){
	fillTree(tree, graph, limit, lowlimit, itype, tanb_values, upper_exclusion, verbosity);
      }
    }
  }
  file->cd();
  tree->Write();
  file->Close();
  delete graph;

  return;
}
Beispiel #9
0
void compareBestFit(const char* filename="test.root", const char* channelstr="boost,vbf,vhtt,cmb+", const char* type="sm", double mass=125, double minimum=-1., double maximum=4.5, const char* label="Preliminary, #sqrt{s}=7-8 TeV, L = 24.3 fb^{-1}, H #rightarrow #tau #tau")
{
  SetStyle();

  std::map<std::string, unsigned int> colors;
  colors["0jet"       ] = kBlue;
  colors["2jet"       ] = kMagenta;
  colors["vbf"        ] = kRed;
  colors["boost"      ] = kGreen;
  colors["btag"       ] = kRed;
  colors["nobtag"     ] = kBlue;
  colors["em"         ] = kBlue;
  colors["et"         ] = kRed;
  colors["mt"         ] = kGreen;
  colors["mm"         ] = kMagenta;
  colors["tt"         ] = kOrange;
  colors["vhtt"       ] = kMagenta+2;
  colors["cmb"        ] = kBlack;
  colors["cmb+"       ] = kGray+2;
  colors["htt"        ] = kBlack;
  colors["ggH"        ] = kRed;
  colors["bbH"        ] = kBlue;
  colors["mvis"       ] = kBlue+2;
  colors["test-0"     ] = kRed+2;
  colors["test-1"     ] = kGreen+2;
  colors["test-2"     ] = kGreen;
  colors["test-3"     ] = kRed+2;
  colors["test-4"     ] = kBlue;
  colors["test-5"     ] = kViolet-6;
  colors["HIG-11-020" ] = kBlue+2;
  colors["HIG-11-029" ] = kRed+2;
  colors["HIG-12-018" ] = kBlue;
  colors["HIG-12-032" ] = kRed+2;
  colors["HIG-12-043" ] = kBlack;
  colors["HIG-12-050" ] = kBlack;

  std::cout << " *******************************************************************************************************\n"
	    << " * Usage     : root -l                                                                                  \n"
	    << " *             .x macros/compareBestFit.C+(file, chn, type)                                             \n"
	    << " *                                                                                                      \n"
	    << " * Arguments :  + file     const char*      full path to the input file                                 \n"
	    << " *              + chn      const char*      list of channels; choose between: 'cmb', 'htt', 'em',       \n"
	    << " *                                          'et', 'mt', 'mm', 'vhtt', 'hgg', 'hww', 'ggH',              \n"
	    << " *                                          'bbH', 'nomix[-200, +200]', 'mhmax[-400, -200, +200]'       \n"
	    << " *                                          'mhmax[+400, +600, +800]', 'test-0...5', 'saeff', 'gluph'   \n"
	    << " *                                          The list should be comma separated and may contain          \n"
	    << " *                                          whitespaces                                                 \n"
	    << " *              + type      const char*     type of plot; choose between 'sm' and 'mssm'                \n"
	    << " *                                                                                                      \n"
	    << " *              + mass      double          Higgs mass for which the plot should be performed           \n"
	    << " *                                                                                                      \n"
	    << " *              + minimum   double          Minimum value for the x-Axis (best fit value)               \n"
	    << " *                                                                                                      \n"
	    << " *              + maximum   double          Maximum value for the x-Axis (best fit value)               \n"
	    << " *                                                                                                      \n"
	    << " *******************************************************************************************************\n";

  /// open input file  
  TFile* inputFile = new TFile(filename); if(inputFile->IsZombie()){ std::cout << "ERROR:: file: " << filename << " does not exist.\n"; }

  /// prepare input parameters
  std::vector<std::string> channels;
  string2Vector(cleanupWhitespaces(channelstr), channels);

  /// prepare histograms
  std::vector<TGraph*> hexp;
  std::vector<TGraph*> hband;
  for(unsigned i=0; i<channels.size(); ++i){
    hexp.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/expected").c_str()));
    hband.push_back(get<TGraph>(inputFile, std::string(channels[i]).append("/innerBand").c_str()));
  }
  int massid = 0; 
  for(int i0  = 0; i0 < hexp[hexp.size()-1]->GetN(); i0++) {   
    double lX = 0; double lY = 0; 
    hexp[hexp.size()-1]->GetPoint(i0, lX, lY);
    if(lX==mass) {massid = i0; break;}
  }
    
  /// do the drawing
  TCanvas* canv1 = new TCanvas("canv1", "Best Fit Comparison", 600, 600);
  canv1->cd();
  canv1->SetGridx(0);
  canv1->SetGridy(0);

  TLine* SM   = new TLine(1, 0, 1, hexp.size());
  TLine* ZERO = new TLine(0, 0, 0, hexp.size());
  
  double *lBestFitX = new double[4];
  double *lBestFitY = new double[4]; 
  lBestFitX[0] = hexp[hexp.size()-1]->Eval(mass) - hband[hband.size()-1]->GetErrorYlow(massid);
  lBestFitX[1] = hexp[hexp.size()-1]->Eval(mass) + hband[hband.size()-1]->GetErrorYhigh(massid);
  lBestFitX[3] = hexp[hexp.size()-1]->Eval(mass) - hband[hband.size()-1]->GetErrorYlow(massid);
  lBestFitX[2] = hexp[hexp.size()-1]->Eval(mass) + hband[hband.size()-1]->GetErrorYhigh(massid);
  lBestFitY[0] = hexp.size();
  lBestFitY[1] = hexp.size();
  lBestFitY[2] = 0;
  lBestFitY[3] = 0;
  TGraph* BAND = new TGraph(4,lBestFitX,lBestFitY); BAND->SetFillColor(kYellow);
  TLine * BEST = new TLine (hexp[hexp.size()-1]->Eval(mass),0,hexp[hexp.size()-1]->Eval(mass),hexp.size()); BEST->SetLineStyle(kDashed); BEST->SetLineColor(kRed);
  bool firstPlot=true;
  for(unsigned int i=0; i<hexp.size(); ++i){
    double value[1] = {hexp[i]->Eval(mass)};
    double position[1] = {hexp.size()-i-0.5}; 

    double x;
    double y;
    double el=0;
    double eh=0;
    int k = hexp[i]->GetN();
    for(int l=0; l<k; l++){
      hexp[i]->GetPoint(l, x, y);
      if(x==mass){
	el=hband[i]->GetErrorYlow(l);
	eh=hband[i]->GetErrorYhigh(l);
	break;
      }
    }

    double elow[1] = {el};
    double ehigh[1] = {eh};
    double help1[1] = {0.0};
    double help2[1] = {0.0};
    TGraphAsymmErrors *gr = new TGraphAsymmErrors(1, value, position, elow, ehigh, help1, help2);
    if(firstPlot){
      if(std::string(type) == std::string("mssm")){
	gr->SetMaximum(hexp.size());
	gr->SetMinimum(0);
      }
      else{
	gr->SetMaximum(hexp.size());
	gr->SetMinimum(0);
      }
      // gr->GetYaxis()->Set(hexp.size(), 0, hexp.size());
      // gr = new TGraphAsymmErrors(1, value, position, elow, ehigh, help1, help2);
      // std::cout << gr->GetYaxis()->GetNbins() << std::endl;
      // format x-axis
      std::string x_title;
      if(std::string(type).find("mssm")!=std::string::npos){
	x_title = std::string("best fit for #sigma(#phi#rightarrow#tau#tau)");
      }
      else{
	x_title = std::string("best fit for #sigma/#sigma_{SM}");
      }
      
      gr->GetXaxis()->SetTitle(x_title.c_str());
      gr->GetXaxis()->SetLabelFont(62);
      gr->GetXaxis()->SetTitleFont(62);
      gr->GetXaxis()->SetTitleColor(1);
      gr->GetXaxis()->SetTitleOffset(1.05);
      gr->GetXaxis()->SetLimits(minimum, maximum);

      BAND->GetXaxis()->SetTitle(x_title.c_str());
      BAND->GetXaxis()->SetLabelFont(62);
      BAND->GetXaxis()->SetTitleFont(62);
      BAND->GetXaxis()->SetTitleColor(1);
      BAND->GetXaxis()->SetTitleOffset(1.05);
      BAND->GetXaxis()->SetLimits(minimum, maximum);

      // format y-axis
      //BAND->GetYaxis()->Set(hexp.size(), 0, hexp.size());
      gr  ->GetYaxis()->Set(hexp.size(), 0, hexp.size());
      //std::cout<<gr->GetYaxis()->GetBinCenter(hexp.size()-i)<<std::endl;
      //BAND->GetYaxis()->SetBinLabel(hexp.size()-1, legendEntry(channels[hexp.size()-1]).c_str());
      for(unsigned int j=0; j<hexp.size(); ++j){
	gr  ->GetYaxis()->SetBinLabel(hexp.size()-j, legendEntry(channels[j]).c_str());
      }
      gr->GetYaxis()->SetTickLength(0);
      gr->GetYaxis()->SetLabelFont(62);
      gr->GetYaxis()->SetTitleFont(62);
      gr->GetYaxis()->SetLabelSize(0.07);
      gr->GetYaxis()->SetTitle("");
      gr->GetYaxis()->SetLabelFont(62);
      gr->GetYaxis()->SetTitleOffset(1.05);
      gr->GetYaxis()->SetLabelSize(0.03);           
      gr->GetYaxis()->SetLabelOffset(-0.32);           

      BAND->GetYaxis()->SetLabelFont(62);
      BAND->GetYaxis()->SetTitleFont(62);
      BAND->GetYaxis()->SetLabelSize(0.07);
      BAND->GetYaxis()->SetTitle("");
      BAND->GetYaxis()->SetLabelFont(62);
      BAND->GetYaxis()->SetTitleOffset(1.05);
      BAND->GetYaxis()->SetLabelSize(0.03);           
      BAND->GetYaxis()->SetLabelOffset(-0.32);           
    }
    BAND->GetYaxis()->SetLabelSize(0.07);
    BAND->SetTitle("");
    gr  ->GetYaxis()->SetLabelSize(0.07);
    gr->SetTitle("");
    gr->SetLineStyle( 1.);
    gr->SetLineWidth( 2.); 
    //gr->SetLineColor(colorzxs.find(channels[i])->second);
    gr->SetLineColor(kBlack);
    gr->SetMarkerStyle(kFullCircle);
    gr->SetMarkerSize(MARKER_SIZE);
    //gr->SetMarkerColor(colors.find(channels[i])->second);
    gr->SetMarkerColor(kBlack);
    cout << "===> " << gr->GetErrorYhigh(0) << endl;
    
    //cout << "==> "<< BAND->GetYaxis()->GetMaximum() << endl;
    if(firstPlot) gr->Draw("AP");  
    if(firstPlot) {
      BAND->Draw("Fsame");  
      BEST->Draw("l");
      TLine *lLine = new TLine(minimum,1.0,maximum,1.0); lLine->SetLineWidth(3); lLine->SetLineColor(kBlue+2);
      lLine->Draw();
      SM->SetLineWidth(3);
      SM->SetLineColor(kGreen+3);
      if(std::string(type).find("mssm")==std::string::npos) SM->Draw("same");
    }
    gr->Draw(firstPlot ? "Psame" : "Psame");
    //gr->Draw(firstPlot ? "AL" : "Lsame");
    firstPlot=false;
  }
  ZERO->SetLineWidth(3);
  ZERO->SetLineColor(kBlue);
  ZERO->SetLineStyle(11);
  //ZERO->Draw("same");
  

  //TPaveText *pt = new TPaveText(2*(maximum+minimum)/3,hexp.size()-0.3,maximum,hexp.size()-0.02);
  TPaveText *pt = new TPaveText(0.76, 0.88, 1.0, 1.0, "NDC");
  if(std::string(type).find("mssm")!=std::string::npos) pt->AddText(TString::Format("m_{A} = %0.0f GeV" , mass));
  else pt->AddText(TString::Format("m_{H} = %0.0f GeV" , mass));
  pt->SetBorderSize(   0 );
  pt->SetFillStyle(    0 );
  pt->SetTextAlign(   12 );
  pt->SetTextSize ( 0.03 );
  pt->SetTextColor(    1 );
  pt->SetTextFont (   62 );
  pt->Draw("same");
  canv1->RedrawAxis();
  CMSPrelim(label, "", 0.15, 0.835);
  
  canv1->Print(std::string("BestFit").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.png" : "_sm.png").c_str());
  canv1->Print(std::string("BestFit").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.pdf" : "_sm.pdf").c_str());
  canv1->Print(std::string("BestFit").append(std::string(type).find("mssm")!=std::string::npos ? "_mssm.pdf" : "_sm.eps").c_str());
  return;
}