Ejemplo n.º 1
0
void makeTFNormalizationPlots()
{
  gROOT->SetBatch(true);

  TH1::AddDirectory(false);

  std::string inputFilePath = "/afs/cern.ch/user/v/veelken/scratch0/CMSSW_5_3_14/src/TauAnalysis/SVfitMEM/";
  std::string inputFileName = "testTFNormalization.root";
  TString inputFileName_full = inputFilePath;
  if ( !inputFileName_full.EndsWith("/") ) inputFileName_full.Append("/");
  inputFileName_full.Append(inputFileName.data());
  TFile* inputFile = new TFile(inputFileName_full.Data());

  TH1* histogram_norm_met    = loadHistogram(inputFile, "", "norm_met");
  TH1* histogram_norm_lepTau = loadHistogram(inputFile, "", "norm_lepTau");
  TH1* histogram_norm_hadTau = loadHistogram(inputFile, "", "norm_hadTau");

  showHistograms(800, 600, 
		 histogram_norm_met,
		 0.99, 1.01, "Normalization", 1.15,
		 true, 1.e0, 2.9e+3, "Toys", 1.20,
		 "plots/norm_met.pdf");
  showHistograms(800, 600, 
		 histogram_norm_lepTau,
		 0.99, 1.01, "Normalization", 1.15,
		 true, 1.e0, 2.9e+3, "Toys", 1.20,
		 "plots/norm_lepTau.pdf");
  showHistograms(800, 600, 
		 histogram_norm_hadTau,
		 0.99, 1.01, "Normalization", 1.15,
		 true, 1.e0, 2.9e+3, "Toys", 1.20,
		 "plots/norm_hadTau.pdf");

  delete inputFile;
}
Ejemplo n.º 2
0
void ColorChooser::loadHistograms(const QImage* imageOriginal)
{
  qApp->processEvents(); // process events just once to fill gray box left over from dropped down menu

  int discretizeMethods = 5;
  int runTime = imageOriginal->width() * discretizeMethods;
  QProgressDialog* dlg = new QProgressDialog(QString(tr("Loading histograms")), "Cancel", 0,
    runTime, m_parent);
  CHECK_PTR_ENGAUGE(dlg);
  dlg->setCaption(tr("Progress"));
  dlg->show();

  loadForegroundPixmap(m_rgbBg);

  intensityHistogram.setAutoDelete(true);
  foregroundHistogram.setAutoDelete(true);
  hueHistogram.setAutoDelete(true);
  saturationHistogram.setAutoDelete(true);
  valueHistogram.setAutoDelete(true);

  loadHistogram(imageOriginal, DiscretizeIntensity, DiscretizeIntensityMax, &intensityHistogram, m_rgbBg, dlg);
  loadHistogram(imageOriginal, DiscretizeForeground, DiscretizeForegroundMax, &foregroundHistogram, m_rgbBg, dlg);
  loadHistogram(imageOriginal, DiscretizeHue, DiscretizeHueMax, &hueHistogram, m_rgbBg, dlg);
  loadHistogram(imageOriginal, DiscretizeSaturation, DiscretizeSaturationMax, &saturationHistogram, m_rgbBg, dlg);
  loadHistogram(imageOriginal, DiscretizeValue, DiscretizeValueMax, &valueHistogram, m_rgbBg, dlg);

  showCurrentHistogram();
  
  chooserCanvas->update();

  ASSERT_ENGAUGE(dlg != 0);
  delete dlg;

  qApp->processEvents(); // process events just once to fill gray box left over from previous window
}
Ejemplo n.º 3
0
void makePlot_shift_minus_central(
       const std::string& inputFilePath_ref, const std::string& inputFileName_ref, 
       const std::string& histogramName_ref_shift, const std::string& histogramName_ref_central, const std::string& legendEntry_ref,
       const std::string& inputFilePath_test, const std::string& inputFileName_test, 
       const std::string& histogramName_test_shift, const std::string& histogramName_test_central, const std::string& legendEntry_test, 
       const std::string& inputFilePath_test2, const std::string& inputFileName_test2, 
       const std::string& histogramName_test2_shift, const std::string& histogramName_test2_central, const std::string& legendEntry_test2,
       const std::string& outputFileName)
{
  std::cout << "<makePlot_shift_minus_central>:" << std::endl;

  TString inputFileName_ref_full = inputFilePath_ref;
  if ( !inputFileName_ref_full.EndsWith("/") ) inputFileName_ref_full.Append("/");
  inputFileName_ref_full.Append(inputFileName_ref.data());
  TFile* inputFile_ref = new TFile(inputFileName_ref_full.Data());
  TH1* histogram_ref_shift = loadHistogram(inputFile_ref, histogramName_ref_shift);
  TH1* histogram_ref_central = loadHistogram(inputFile_ref, histogramName_ref_central);
  TH1* histogram_ref_shift_minus_centralAbs = 0;
  TH1* histogram_ref_shift_minus_centralRel = 0;
  double integral_ref = -1.;
  if ( histogram_ref_shift && histogram_ref_central ) {
    std::string histogramName_ref_shift_minus_centralAbs = Form("%s_minus_%sAbs", histogram_ref_shift->GetName(), histogram_ref_central->GetName());
    histogram_ref_shift_minus_centralAbs = subtractHistograms(histogramName_ref_shift_minus_centralAbs, histogram_ref_shift, histogram_ref_central, kAbsolute);
    std::string histogramName_ref_shift_minus_centralRel = Form("%s_minus_%sRel", histogram_ref_shift->GetName(), histogram_ref_central->GetName());
    histogram_ref_shift_minus_centralRel = subtractHistograms(histogramName_ref_shift_minus_centralRel, histogram_ref_shift, histogram_ref_central, kRelative);
    integral_ref = compIntegral(histogram_ref_shift_minus_centralAbs);
    std::cout << " integral_ref = " << integral_ref << std::endl;
    divideByBinWidth(histogram_ref_shift_minus_centralAbs);
  }

  TString inputFileName_test_full = inputFilePath_test;
  if ( !inputFileName_test_full.EndsWith("/") ) inputFileName_test_full.Append("/");
  inputFileName_test_full.Append(inputFileName_test.data());
  TFile* inputFile_test = ( inputFileName_test_full != inputFileName_ref_full ) ? 
    new TFile(inputFileName_test_full.Data()) : inputFile_ref;
  TH1* histogram_test_shift = loadHistogram(inputFile_test, histogramName_test_shift);
  TH1* histogram_test_central = loadHistogram(inputFile_test, histogramName_test_central);
  TH1* histogram_test_shift_minus_centralAbs = 0;
  TH1* histogram_test_shift_minus_centralRel = 0;
  double integral_test = -1.;
  if ( histogram_test_shift && histogram_test_central ) {
    std::string histogramName_test_shift_minus_centralAbs = Form("%s_minus_%sAbs", histogram_test_shift->GetName(), histogram_test_central->GetName());
    histogram_test_shift_minus_centralAbs = subtractHistograms(histogramName_test_shift_minus_centralAbs, histogram_test_shift, histogram_test_central, kAbsolute);
    std::string histogramName_test_shift_minus_centralRel = Form("%s_minus_%sRel", histogram_test_shift->GetName(), histogram_test_central->GetName());
    histogram_test_shift_minus_centralRel = subtractHistograms(histogramName_test_shift_minus_centralRel, histogram_test_shift, histogram_test_central, kRelative);
    integral_test = compIntegral(histogram_test_shift_minus_centralAbs);
    std::cout << " integral_test = " << integral_test << std::endl;
    divideByBinWidth(histogram_test_shift_minus_centralAbs);
  }

  TFile* inputFile_test2 = 0;
  TH1* histogram_test2_shift_minus_centralAbs = 0;
  TH1* histogram_test2_shift_minus_centralRel = 0;
  double integral_test2 = -1.;
  if ( inputFilePath_test2 != "" && inputFileName_test2 != "" && histogramName_test2_shift != "" && histogramName_test2_central != "" ) {
    TString inputFileName_test2_full = inputFilePath_test2;
    if ( !inputFileName_test2_full.EndsWith("/") ) inputFileName_test2_full.Append("/");
    inputFileName_test2_full.Append(inputFileName_test2.data());
    inputFile_test2 = ( inputFileName_test2_full != inputFileName_ref_full ) ? 
      new TFile(inputFileName_test2_full.Data()) : inputFile_ref;
    TH1* histogram_test2_shift = loadHistogram(inputFile_test2, histogramName_test2_shift);
    TH1* histogram_test2_central = loadHistogram(inputFile_test2, histogramName_test2_central);
    if ( histogram_test2_shift && histogram_test2_central ) {
      std::string histogramName_test2_shift_minus_centralAbs = Form("%s_minus_%sAbs", histogram_test2_shift->GetName(), histogram_test2_central->GetName());
      histogram_test2_shift_minus_centralAbs = subtractHistograms(histogramName_test2_shift_minus_centralAbs, histogram_test2_shift, histogram_test2_central, kAbsolute);
      std::string histogramName_test2_shift_minus_centralRel = Form("%s_minus_%sRel", histogram_test2_shift->GetName(), histogram_test2_central->GetName());
      histogram_test2_shift_minus_centralRel = subtractHistograms(histogramName_test2_shift_minus_centralRel, histogram_test2_shift, histogram_test2_central, kRelative);
      integral_test2 = compIntegral(histogram_test2_shift_minus_centralAbs);
      std::cout << " integral_test2 = " << integral_test2 << std::endl;
      divideByBinWidth(histogram_test2_shift_minus_centralAbs);
    }
  }

  size_t idx = outputFileName.find_last_of('.');
  std::string outputFileName_abs = std::string(outputFileName, 0, idx);
  outputFileName_abs.append("_absolute");
  if ( idx != std::string::npos ) outputFileName_abs.append(std::string(outputFileName, idx));

  showHistograms(800, 900, 
		 histogram_ref_shift_minus_centralAbs, legendEntry_ref, integral_ref,
		 histogram_test_shift_minus_centralAbs, legendEntry_test, integral_test, 
		 histogram_test2_shift_minus_centralAbs, legendEntry_test2, integral_test2, 
		 //NULL, "", 0.,
		 NULL, "", 0.,
		 NULL, "", 0.,
		 NULL, "", 0.,
		 "m_{#tau#tau} [GeV]", 1.10,
		 true, 1.e-4, 1.e+4, "1/dm_{#tau#tau} [1/GeV]", 1.30,
		 0.34, 0.72,
		 outputFileName_abs.data());
  
  std::string outputFileName_rel = std::string(outputFileName, 0, idx);
  outputFileName_rel.append("_relative");
  if ( idx != std::string::npos ) outputFileName_rel.append(std::string(outputFileName, idx));
  
  showHistograms(800, 900, 
		 histogram_ref_shift_minus_centralRel, legendEntry_ref, integral_ref,
		 histogram_test_shift_minus_centralRel, legendEntry_test, integral_test, 
		 histogram_test2_shift_minus_centralRel, legendEntry_test2, integral_test2, 
		 //NULL, "", 0.,
		 NULL, "", 0.,
		 NULL, "", 0.,
		 NULL, "", 0.,
		 "m_{#tau#tau} [GeV]", 1.10,
		 true, 1.e-4, 1.e+4, "#Delta 1/dm_{#tau#tau}", 1.30,
		 0.34, 0.72,
		 outputFileName_rel.data());

  delete inputFile_ref;
  if ( inputFile_test != inputFile_ref ) delete inputFile_test;
  if ( inputFile_test2 != inputFile_ref && inputFile_test2 != inputFile_test ) delete inputFile_test2;
}
Ejemplo n.º 4
0
void makePlot(
       const std::string& inputFilePath_ref, const std::string& inputFileName_ref, const std::string& histogramName_ref, const std::string& legendEntry_ref,
       const std::string& inputFilePath_test, const std::string& inputFileName_test, const std::string& histogramName_test, const std::string& legendEntry_test, 
       const std::string& inputFilePath_test2, const std::string& inputFileName_test2, const std::string& histogramName_test2, const std::string& legendEntry_test2,
       const std::string& outputFileName)
{
  std::cout << "<makePlot_shift_minus_central>:" << std::endl;

  TString inputFileName_ref_full = inputFilePath_ref;
  if ( !inputFileName_ref_full.EndsWith("/") ) inputFileName_ref_full.Append("/");
  inputFileName_ref_full.Append(inputFileName_ref.data());
  TFile* inputFile_ref = new TFile(inputFileName_ref_full.Data());
  TH1* histogram_ref = loadHistogram(inputFile_ref, histogramName_ref);
  double integral_ref = compIntegral(histogram_ref);
  divideByBinWidth(histogram_ref);

  TString inputFileName_test_full = inputFilePath_test;
  if ( !inputFileName_test_full.EndsWith("/") ) inputFileName_test_full.Append("/");
  inputFileName_test_full.Append(inputFileName_test.data());
  TFile* inputFile_test = ( inputFileName_test_full != inputFileName_ref_full ) ? 
    new TFile(inputFileName_test_full.Data()) : inputFile_ref;
  TH1* histogram_test = loadHistogram(inputFile_test, histogramName_test);
  double integral_test = compIntegral(histogram_test);
  divideByBinWidth(histogram_test);
  
  TFile* inputFile_test2 = 0;
  TH1* histogram_test2 = 0;
  double integral_test2 = -1.;
  if ( inputFilePath_test2 != "" && inputFileName_test2 != "" && histogramName_test2 != "" ) {
    TString inputFileName_test2_full = inputFilePath_test2;
    if ( !inputFileName_test2_full.EndsWith("/") ) inputFileName_test2_full.Append("/");
    inputFileName_test2_full.Append(inputFileName_test2.data());
    inputFile_test2 = ( inputFileName_test2_full != inputFileName_ref_full ) ? 
      new TFile(inputFileName_test2_full.Data()) : inputFile_ref;
    histogram_test2 = loadHistogram(inputFile_test2, histogramName_test2);
    integral_test2 = compIntegral(histogram_test2);
    divideByBinWidth(histogram_test2);
  }
  
  showHistograms(800, 900, 
		 histogram_ref, legendEntry_ref, integral_ref,
		 histogram_test, legendEntry_test, integral_test, 
		 histogram_test2, legendEntry_test2, integral_test2, 
		 //NULL, "", 0.,
		 NULL, "", 0.,
		 NULL, "", 0.,
		 NULL, "", 0.,
		 "m_{#tau#tau} [GeV]", 1.10,
		 true, 1.e-4, 1.e+4, "1/dm_{#tau#tau} [1/GeV]", 1.30,
		 0.34, 0.72,
		 outputFileName.data());

  TH1* histogramErr_ref = compHistogramErr(histogram_ref);
  TH1* histogramErr_test = compHistogramErr(histogram_test);
  TH1* histogramErr_test2 = ( histogram_test2 ) ?
    compHistogramErr(histogram_test2) : 0;
  std::string outputFileNameErr = TString(outputFileName.data()).ReplaceAll(".png", "_Err.png").Data();
  showHistograms(800, 900, 
		 histogramErr_ref, legendEntry_ref, -1.,
		 histogramErr_test, legendEntry_test, -1., 
		 histogramErr_test2, legendEntry_test2, -1., 
		 //NULL, "", 0.,
		 NULL, "", 0.,
		 NULL, "", 0.,
		 NULL, "", 0.,
		 "m_{#tau#tau} [GeV]", 1.10,
		 true, 1.e-4, 1.e+4, "#sigma(1/dm_{#tau#tau}) [1/GeV]", 1.30,
		 0.34, 0.72,
		 outputFileNameErr.data());

  delete histogramErr_ref;
  delete histogramErr_test;
  delete histogramErr_test2;
  
  delete inputFile_ref;
  if ( inputFile_test != inputFile_ref ) delete inputFile_test;
  if ( inputFile_test2 != inputFile_ref && inputFile_test2 != inputFile_test ) delete inputFile_test2;
}
void makePostFitPlots_1l_2tau()
{
  gROOT->SetBatch(true);

  TH1::AddDirectory(false);

  std::vector<std::string> categories;
  categories.push_back("ttH_1l_2tau_prefit");
  categories.push_back("ttH_1l_2tau_postfit");

  std::string inputFilePath = string(getenv("CMSSW_BASE")) + "/src/CombineHarvester/ttH_htt/";
  std::map<std::string, std::string> inputFileNames; // key = category
  inputFileNames["ttH_1l_2tau_prefit"]  = "ttH_1l_2tau_shapes.root";
  inputFileNames["ttH_1l_2tau_postfit"] = "ttH_1l_2tau_shapes.root";
  
  for ( std::vector<std::string>::const_iterator category = categories.begin();
	category != categories.end(); ++category ) {
    std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileNames[*category].data());
    TFile* inputFile = new TFile(inputFileName_full.data());
    if ( !inputFile ) {
      std::cerr << "Failed to open input file = " << inputFileName_full << " !!" << std::endl;
      assert(0);
    }

    TH1* histogramTTH_hww = loadHistogram(inputFile, *category, "ttH_hww");
    TH1* histogramTTH_hzz = loadHistogram(inputFile, *category, "ttH_hzz");
    TH1* histogramTTH_htt = loadHistogram(inputFile, *category, "ttH_htt");
    TString histogramNameTTH = TString(histogramTTH_hww->GetName()).ReplaceAll("_hww", "_sum");
    TH1* histogramTTH = (TH1*)histogramTTH_hww->Clone(histogramNameTTH.Data());
    histogramTTH->Add(histogramTTH_hzz);
    histogramTTH->Add(histogramTTH_htt);

    TH1* histogramData = loadHistogram(inputFile, *category, "data_obs");

    TH1* histogramTT = loadHistogram(inputFile, *category, "TT");

    TH1* histogramTTW = loadHistogram(inputFile, *category, "TTW");
    TH1* histogramTTZ = loadHistogram(inputFile, *category, "TTZ");
    TString histogramNameTTV = "TTV";
    TH1* histogramTTV = (TH1*)histogramTTW->Clone(histogramNameTTV.Data());
    histogramTTV->Add(histogramTTZ);

    TH1* histogramEWK = loadHistogram(inputFile, *category, "EWK");

    TH1* histogramRares = loadHistogram(inputFile, *category, "Rares");

    TH1* histogramBgrSum = loadHistogram(inputFile, *category, "TotalBkg");
    TH1* histogramBgrUncertainty = (TH1*)histogramBgrSum->Clone("TotalBkgErr");

    std::string outputFileName = Form("plots/makePostFitPlots_%s.pdf", category->data());
    makePlot(800, 900,
	     histogramTTH,
	     histogramData, 
	     histogramTT,
	     histogramTTV,
	     histogramEWK,
	     histogramRares,
	     histogramBgrSum,
	     histogramBgrUncertainty,	
	     "m_{#tau#tau}^{vis}", 0.9,
	     true, 3.e-4, 3.e0, "Events", 0.9,
	     outputFileName);

    delete histogramTTH;
    delete histogramTTV;
    delete histogramBgrUncertainty;

    delete inputFile;
  }
}
void makePostFitPlots_3l_1tau()
{
  gROOT->SetBatch(true);

  TH1::AddDirectory(false);

  std::vector<std::string> categories;
  categories.push_back("ttH_3l_1tau_prefit");
  categories.push_back("ttH_3l_1tau_postfit");

  std::string inputFilePath = string(getenv("CMSSW_BASE")) + "/src/CombineHarvester/ttH_htt/limits/";
  std::map<std::string, std::string> inputFileNames; // key = category
  inputFileNames["ttH_3l_1tau_prefit"]  = "ttH_3l_1tau_mvaDiscr_3l_2016_shapes.root";
  inputFileNames["ttH_3l_1tau_postfit"] = "ttH_3l_1tau_mvaDiscr_3l_2016_shapes.root";
  
  bool doKeepBlinded = true;
  //bool doKeepBlinded = false;

  for ( std::vector<std::string>::const_iterator category = categories.begin();
	category != categories.end(); ++category ) {
    std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileNames[*category].data());
    TFile* inputFile = new TFile(inputFileName_full.data());
    if ( !inputFile ) {
      std::cerr << "Failed to open input file = " << inputFileName_full << " !!" << std::endl;
      assert(0);
    }

    TH1* histogram_data = loadHistogram(inputFile, *category, "data_obs");
    std::cout << "histogram_data = " << histogram_data << ":" << std::endl;
    if ( !doKeepBlinded ) {
      dumpHistogram(histogram_data);
    }


    TH1* histogram_ttH_htt = loadHistogram(inputFile, *category, "ttH_htt");
    TH1* histogram_ttH_hww = loadHistogram(inputFile, *category, "ttH_hww");
    TH1* histogram_ttH_hzz = loadHistogram(inputFile, *category, "ttH_hzz");
    std::cout << "histogram_ttH: htt = " << histogram_ttH_htt << ", hww = " << histogram_ttH_hww << ", hzz = " << histogram_ttH_hzz << std::endl;
    TString histogramName_ttH = TString(histogram_ttH_htt->GetName()).ReplaceAll("_htt", "_sum");
    TH1* histogram_ttH = (TH1*)histogram_ttH_htt->Clone(histogramName_ttH.Data());
    histogram_ttH->Add(histogram_ttH_hww);
    histogram_ttH->Add(histogram_ttH_hzz);
    makeBinContentsPositive(histogram_ttH);
    std::cout << "histogram_ttH = " << histogram_ttH << ":" << std::endl;
    dumpHistogram(histogram_ttH);

    TH1* histogram_ttZ = loadHistogram(inputFile, *category, "TTZ");
    std::cout << "histogram_ttZ = " << histogram_ttZ << std::endl;
    makeBinContentsPositive(histogram_ttZ);
    dumpHistogram(histogram_ttZ);
    
    TH1* histogram_ttW = loadHistogram(inputFile, *category, "TTW");
    std::cout << "histogram_ttW = " << histogram_ttW << std::endl;
    makeBinContentsPositive(histogram_ttW);
    dumpHistogram(histogram_ttW);
    
    TH1* histogram_EWK = loadHistogram(inputFile, *category, "EWK");    
    std::cout << "histogram_EWK = " << histogram_EWK << std::endl;
    makeBinContentsPositive(histogram_EWK);
    dumpHistogram(histogram_EWK);

    TH1* histogram_Rares = loadHistogram(inputFile, *category, "Rares");
    std::cout << "histogram_Rares = " << histogram_Rares << std::endl;
    makeBinContentsPositive(histogram_Rares);
    dumpHistogram(histogram_Rares);

    TH1* histogram_fakes = loadHistogram(inputFile, *category, "fakes_data");
    std::cout << "histogram_fakes = " << histogram_fakes << std::endl;
    makeBinContentsPositive(histogram_fakes);
    dumpHistogram(histogram_fakes);

    TH1* histogramSum_mcBgr = loadHistogram(inputFile, *category, "TotalBkg");
    std::cout << "histogramSum_mcBgr = " << histogramSum_mcBgr << std::endl;
    makeBinContentsPositive(histogramSum_mcBgr);
    dumpHistogram(histogramSum_mcBgr);
    TH1* histogramSum_mc = (TH1*)histogramSum_mcBgr->Clone("histogramSum_mc");
    histogramSum_mc->Add(histogram_ttH);
    std::cout << "histogramSum_mc = " << histogramSum_mc << std::endl;
    TH1* histogramErr_mc = (TH1*)histogramSum_mc->Clone("TotalBkgErr");

    std::string outputFilePath = string(getenv("CMSSW_BASE")) + "/src/CombineHarvester/ttH_htt/macros";
    std::string outputFileName = Form("%s/plots/makePostFitPlots_%s.pdf", outputFilePath.data(), category->data());
    makePlot(histogram_data, doKeepBlinded,
	     histogram_ttH, 
	     histogram_ttZ,
	     histogram_ttW,
	     histogram_EWK,
	     histogram_Rares,
	     histogram_fakes,
	     histogramSum_mc,
	     histogramErr_mc,		
	     "MVA Discriminator", 
	     "Events", 1.01e-2, 1.99e+1, 
	     true,
	     "3l_1tau",
	     outputFileName,
	     true);

    delete histogram_ttH;
    delete histogramErr_mc;
    delete inputFile;
  }
}