void makePlots_hlt_eventbyevent_comparison( std::string inputFile_="input.root", std::string target_label_="Target", std::string outputSuffix_="_out" ) {

  TFile *file = new TFile(inputFile_.c_str());

  std::string dirprefix = "Images" + outputSuffix_;
  struct stat st;
  if( stat(dirprefix.c_str(),&st) != 0 )  mkdir(dirprefix.c_str(),0777);

  std::string label_ref = "Reference";
  std::string label_tgt = target_label_;

  TH1D* h_ref = (TH1D*)file->Get("eventbyevent/HLT_Ref");
  TH1D* h_tgt = (TH1D*)file->Get("eventbyevent/HLT_Tgt");
  TH1D* h_tgt_sep = (TH1D*)file->Get("eventbyevent/HLT_Tgt_sep");

  std::map<std::string, int> hlt_counts_per_path_ref_;
  std::map<std::string, int> hlt_counts_per_path_tgt_;
  std::map<double, std::string> hlt_counts_per_path_diff_;

  std::vector<std::string> hlt_common_paths;

  TAxis * axis = h_ref->GetXaxis();

  // loop over target paths
  for( int iPath=0; iPath<h_tgt_sep->GetNbinsX(); iPath++ ){
    std::string name(h_tgt_sep->GetXaxis()->GetBinLabel(iPath+1));
    
    int bin = axis->FindBin(name.c_str());

    if( bin<1 ) continue;

    double cnt_ref = h_ref->GetBinContent(bin);
    double cnt_tgt = h_tgt->GetBinContent(bin);

    int diff = int( cnt_ref - cnt_tgt );
    double rel_diff = double(diff);

    if( cnt_ref>0 )      rel_diff = fabs(cnt_tgt - cnt_ref)/cnt_ref;
    else if( cnt_tgt>0 ) rel_diff = fabs(cnt_tgt - cnt_ref)/cnt_tgt;
    else                 rel_diff = 0.;

    // printf("%s\t %d\t %d\t %d\t %.3f \n",
    // 	   name.c_str(), int(cnt_ref), int(cnt_tgt), diff, rel_diff ); 

    hlt_counts_per_path_ref_[name] = int(cnt_ref);
    hlt_counts_per_path_tgt_[name] = int(cnt_tgt);

    hlt_counts_per_path_diff_[rel_diff] = name;

    if( rel_diff>0.15 ) hlt_common_paths.push_back(name);
  }


  std::map<double, std::string>::reverse_iterator rit;
  for( rit=hlt_counts_per_path_diff_.rbegin(); rit!=hlt_counts_per_path_diff_.rend(); ++rit )
    std::cout << "path: " << rit->second << "\t" << rit->first << "\t" << hlt_counts_per_path_ref_[rit->second] << "\t" << hlt_counts_per_path_tgt_[rit->second] << std::endl;


  int numPaths = int( hlt_counts_per_path_ref_.size() );
  TH1D* h_hlt_ref = new TH1D("h_hlt_ref",";HLT path", numPaths, 0, numPaths );
  TH1D* h_hlt_tgt = new TH1D("h_hlt_tgt",";HLT path", numPaths, 0, numPaths );
  TH1D* h_hlt_diff = new TH1D("h_hlt_diff",";HLT path", numPaths, 0, numPaths );

  int iHLT=0;
  for( std::map<std::string, int>::iterator it=hlt_counts_per_path_ref_.begin(); it!=hlt_counts_per_path_ref_.end(); ++it ){
    iHLT++;
    std::string name = it->first;

    double cnt_ref = double(hlt_counts_per_path_ref_[name]);
    double cnt_tgt = double(hlt_counts_per_path_tgt_[name]);

    double rel_diff = 1.0;
    if( cnt_ref>0 )      rel_diff = (cnt_tgt - cnt_ref)/cnt_ref;
    else if( cnt_tgt>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_tgt;
    else                 rel_diff = 0.;

    h_hlt_ref->SetBinContent(iHLT,cnt_ref);
    h_hlt_tgt->SetBinContent(iHLT,cnt_tgt);
    h_hlt_diff->SetBinContent(iHLT,rel_diff);

    h_hlt_ref->GetXaxis()->SetBinLabel(iHLT,name.c_str());
    h_hlt_diff->GetXaxis()->SetBinLabel(iHLT,name.c_str());
  }


  h_hlt_ref->SetStats(0);

  h_hlt_ref->SetLineColor(kBlue);
  h_hlt_tgt->SetLineColor(kRed);

  if( true ){
    // TLegend *legend = new TLegend(0.255,0.78,0.92,0.89);
    TLegend *legend = new TLegend(0.255,0.92,0.92,0.99);

    legend->SetFillColor(kWhite);
    legend->SetLineColor(kWhite);
    legend->SetShadowColor(kWhite);
    legend->SetTextFont(42);
    legend->SetTextSize(0.035);

    legend->SetNColumns(2);

    legend->AddEntry(h_hlt_ref,label_ref.c_str(),"l");
    legend->AddEntry(h_hlt_tgt,label_tgt.c_str(),"l");


    //// Original
    // double ratioMin = -1.2;
    // double ratioMax = 1.2;
    double ratioMin = -0.6;
    double ratioMax = 0.6;

    //Hack to get it plotted with ratio plot
    TCanvas* myC = new TCanvas("myC", "myC", 1200,700);

    gStyle->SetPadBorderMode(0);
    gStyle->SetFrameBorderMode(0);
    Float_t small = 1.e-5;
    myC->Divide(1,2,small,small);
    const float padding=1e-5; const float ydivide=0.3;
    myC->GetPad(1)->SetPad( padding, ydivide + padding , 1-padding, 1-padding);
    myC->GetPad(2)->SetPad( padding, padding, 1-padding, ydivide-padding);
    myC->GetPad(1)->SetLeftMargin(.11);
    myC->GetPad(2)->SetLeftMargin(.11);
    myC->GetPad(1)->SetRightMargin(.05);
    myC->GetPad(2)->SetRightMargin(.05);
    myC->GetPad(1)->SetBottomMargin(.3);
    myC->GetPad(2)->SetBottomMargin(.3);
    myC->GetPad(1)->Modified();
    myC->GetPad(2)->Modified();
    myC->cd(1);
    gPad->SetBottomMargin(small);
    gPad->Modified();



    TH1D* myRatio = (TH1D*)h_hlt_diff->Clone("myRatio");

    myRatio->SetStats(0);
    myRatio->Sumw2();
    myRatio->SetLineColor(kBlack);
    myRatio->SetMarkerColor(kBlack);

    myRatio->SetMinimum(ratioMin);
    myRatio->SetMaximum(ratioMax);
    //myRatio->GetYaxis()->SetNdivisions(50000+404);
    myRatio->GetYaxis()->SetNdivisions(20000+505);
    myRatio->GetYaxis()->SetLabelSize(0.1); //make y label bigger
    myRatio->GetXaxis()->SetLabelSize(0.1); //make y label bigger
    myRatio->GetXaxis()->SetTitleOffset(1.1);
    myRatio->GetXaxis()->SetTitle(h_hlt_diff->GetXaxis()->GetTitle()); //make y label bigger
    myRatio->GetXaxis()->SetLabelSize(0.12);
    myRatio->GetXaxis()->SetLabelOffset(0.04);
    myRatio->GetXaxis()->SetTitleSize(0.12);
    // myRatio->GetYaxis()->SetTitle("Data/MC");
    myRatio->GetYaxis()->SetTitle("New - Old / Old");
    myRatio->GetYaxis()->SetTitleSize(0.1);
    myRatio->GetYaxis()->SetTitleOffset(.45);
    myC->cd(2);
    gPad->SetTopMargin(small);
    gPad->SetTickx();
    gPad->Modified();

    myC->cd(1);

    h_hlt_ref->GetYaxis()->SetTitle("Number of Events");
    h_hlt_ref->GetYaxis()->SetTitleSize(0.05);
    h_hlt_ref->GetYaxis()->SetTitleOffset(.95);

    h_hlt_ref->Draw();
    h_hlt_tgt->Draw("same");

    legend->Draw();

    double xmin = h_hlt_ref->GetBinLowEdge(1);
    double xmax = h_hlt_ref->GetBinLowEdge(h_hlt_ref->GetNbinsX()) + h_hlt_ref->GetBinWidth(h_hlt_ref->GetNbinsX());

    myC->cd(2);

    myRatio->SetLineWidth(2);

    myRatio->Draw("hist");

    TLine* myLine;
    myLine = new TLine(xmin, 0, xmax, 0);
    myLine->Draw();

    std::string outputFile = dirprefix + "/hlt_path_comparison" + outputSuffix_ + ".pdf";
    myC->Print(outputFile.c_str());

    delete legend;
    delete myC;
    delete myLine;
  }


  if( true ){
    int numCommonPaths = int(hlt_common_paths.size());

    for( int iPath=0; iPath<numCommonPaths; iPath++ ){
      std::cout << " ====================== " << std::endl;
      std::string name = hlt_common_paths[iPath];
      std::string pathName_ref = "eventbyevent/h_path_ref_" + name;
      std::string pathName_tgt = "eventbyevent/h_path_tgt_" + name;

      std::string diffname = "h_path_diff_" + name;

      //std::cout << " path is " << pathName_ref << std::endl;

      if( name=="HLT_LogMonitor" ) continue;

      TH1D* h_hlt_filt_ref = (TH1D*)file->Get(pathName_ref.c_str());
      TH1D* h_hlt_filt_tgt = (TH1D*)file->Get(pathName_tgt.c_str());
      TH1D* h_hlt_filt_diff = (TH1D*)h_hlt_filt_ref->Clone(diffname.c_str());

      bool printOut = true;
      for( int iBin=0; iBin<h_hlt_filt_tgt->GetNbinsX(); iBin++ ){
	double cnt_ref = h_hlt_filt_ref->GetBinContent(iBin+1);
	double cnt_tgt = h_hlt_filt_tgt->GetBinContent(iBin+1);

	double rel_diff = 1.0;
	if( cnt_ref>0 )      rel_diff = (cnt_tgt - cnt_ref)/cnt_ref;
	else if( cnt_tgt>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_tgt;
	else                 rel_diff = 0.;

	h_hlt_filt_diff->SetBinContent(iBin+1,rel_diff);

	//if( fabs(rel_diff)>0.0002 ) printOut = true;
      }

      if( printOut ){
	double cnt_ref = double(hlt_counts_per_path_ref_[name]);
	double cnt_tgt = double(hlt_counts_per_path_tgt_[name]);

	double rel_diff = 1.0;
	if( cnt_ref>0 )      rel_diff = (cnt_tgt - cnt_ref)/cnt_ref;
	else if( cnt_tgt>0 ) rel_diff = (cnt_tgt - cnt_ref)/cnt_tgt;
	else                 rel_diff = 0.;

	printf("%s: relative difference = %.3f,\t reference = %d,\t target = %d \n",
	       name.c_str(), rel_diff, hlt_counts_per_path_ref_[name], hlt_counts_per_path_tgt_[name]);

	for( int iBin=0; iBin<h_hlt_filt_tgt->GetNbinsX(); iBin++ ){
	  double my_cnt_ref = h_hlt_filt_ref->GetBinContent(iBin+1);
	  double my_cnt_tgt = h_hlt_filt_tgt->GetBinContent(iBin+1);

	  double my_rel_diff = 1.0;
	  if( my_cnt_ref>0 )      my_rel_diff = (my_cnt_tgt - my_cnt_ref)/my_cnt_ref;
	  else if( my_cnt_tgt>0 ) my_rel_diff = (my_cnt_tgt - my_cnt_ref)/my_cnt_tgt;
	  else                   my_rel_diff = 0.;

	  printf("\t %s \t %.3f \t %.0f \t %.0f \n",
		 h_hlt_filt_ref->GetXaxis()->GetBinLabel(iBin+1), my_rel_diff, my_cnt_ref, my_cnt_tgt);
	}
      }

      h_hlt_filt_ref->SetStats(0);

      h_hlt_filt_ref->SetLineColor(kBlue);
      h_hlt_filt_tgt->SetLineColor(kRed);

      //TLegend *legend = new TLegend(0.255,0.78,0.92,0.89);
      TLegend *legend = new TLegend(0.255,0.92,0.92,0.99);

      legend->SetFillColor(kWhite);
      legend->SetLineColor(kWhite);
      legend->SetShadowColor(kWhite);
      legend->SetTextFont(42);
      legend->SetTextSize(0.035);

      legend->SetNColumns(2);

      legend->AddEntry(h_hlt_filt_ref,label_ref.c_str(),"l");
      legend->AddEntry(h_hlt_filt_tgt,label_tgt.c_str(),"l");


      double ratioMin = -1.2;
      double ratioMax = 1.2;

      //Hack to get it plotted with ratio plot
      TCanvas* myC = new TCanvas("myC", "myC", 600,700);

      gStyle->SetPadBorderMode(0);
      gStyle->SetFrameBorderMode(0);
      Float_t small = 1.e-5;
      myC->Divide(1,2,small,small);
      const float padding=1e-5; const float ydivide=0.3;
      myC->GetPad(1)->SetPad( padding, ydivide + padding , 1-padding, 1-padding);
      myC->GetPad(2)->SetPad( padding, padding, 1-padding, ydivide-padding);
      myC->GetPad(1)->SetLeftMargin(.11);
      myC->GetPad(2)->SetLeftMargin(.11);
      myC->GetPad(1)->SetRightMargin(.05);
      myC->GetPad(2)->SetRightMargin(.05);
      myC->GetPad(1)->SetBottomMargin(.3);
      myC->GetPad(2)->SetBottomMargin(.3);
      myC->GetPad(1)->Modified();
      myC->GetPad(2)->Modified();
      myC->cd(1);
      gPad->SetBottomMargin(small);
      gPad->Modified();



      TH1D* myRatio = (TH1D*)h_hlt_filt_diff->Clone();

      myRatio->SetStats(0);
      myRatio->Sumw2();
      myRatio->SetLineColor(kBlack);
      myRatio->SetMarkerColor(kBlack);

      myRatio->SetMinimum(ratioMin);
      myRatio->SetMaximum(ratioMax);
      myRatio->GetYaxis()->SetNdivisions(50000+404);
      myRatio->GetYaxis()->SetLabelSize(0.1); //make y label bigger
      myRatio->GetXaxis()->SetLabelSize(0.1); //make y label bigger
      myRatio->GetXaxis()->SetTitleOffset(1.1);
      myRatio->GetXaxis()->SetTitle(h_hlt_diff->GetXaxis()->GetTitle()); //make y label bigger
      myRatio->GetXaxis()->SetLabelSize(0.12);
      myRatio->GetXaxis()->SetLabelOffset(0.04);
      myRatio->GetXaxis()->SetTitleSize(0.12);
      // myRatio->GetYaxis()->SetTitle("Data/MC");
      myRatio->GetYaxis()->SetTitle("New - Old / Old");
      myRatio->GetYaxis()->SetTitleSize(0.1);
      myRatio->GetYaxis()->SetTitleOffset(.45);
      myC->cd(2);
      gPad->SetTopMargin(small);
      gPad->SetTickx();
      gPad->Modified();

      myC->cd(1);

      h_hlt_filt_ref->GetYaxis()->SetTitle("Number of Events");
      h_hlt_filt_ref->GetYaxis()->SetTitleSize(0.05);
      h_hlt_filt_ref->GetYaxis()->SetTitleOffset(.95);

      h_hlt_filt_ref->Draw();
      h_hlt_filt_tgt->Draw("same");

      legend->Draw();

      double xmin = h_hlt_filt_ref->GetBinLowEdge(1);
      double xmax = h_hlt_filt_ref->GetBinLowEdge(h_hlt_filt_ref->GetNbinsX()) + h_hlt_filt_ref->GetBinWidth(h_hlt_filt_ref->GetNbinsX());

      myC->cd(2);

      myRatio->SetLineWidth(2);

      myRatio->Draw("hist");

      TLine* myLine;
      myLine = new TLine(xmin, 0, xmax, 0);
      myLine->Draw();

      std::string outputFile = dirprefix + "/hlt_path_" + name + outputSuffix_ + ".pdf";
      myC->Print(outputFile.c_str());

      delete legend;
      delete myC;
      delete myLine;
    }
    std::cout << " ====================== " << std::endl;

  }

  // close file
  file->Close();

}
示例#2
0
void drawChannelYieldPlot( DrawBase* db, const std::string& selType, const std::string& bTaggerType, float lumi_fb, const std::string& saveName, std::string additionalCuts ) {


  if( additionalCuts!="" ) additionalCuts += " && ";

  // and now lepton channel definitions:
  std::string sel_mmm = "eventWeight*( " + additionalCuts + " isMZllSignalRegion && leptType==0 && leptType3==0)";
  std::string sel_mme = "eventWeight*( " + additionalCuts + " isMZllSignalRegion && leptType==0 && leptType3==1)";
  std::string sel_eem = "eventWeight*( " + additionalCuts + " isMZllSignalRegion && leptType==1 && leptType3==0)";
  std::string sel_eee = "eventWeight*( " + additionalCuts + " isMZllSignalRegion && leptType==1 && leptType3==1)";



  TLegend* legend = new TLegend( 0.6, 0.57, 0.92, 0.9 );
  legend->SetFillColor(0);
  legend->SetTextSize(0.042);


  THStack* stackMC = new THStack();
  std::vector<TH1D*> vh1_yields_mc;

  std::string yieldsFileName = "yields_"+selType;
  if( saveName!= "" ) yieldsFileName = yieldsFileName + "_" + saveName;
  yieldsFileName = yieldsFileName +"_"+bTaggerType+".txt";

  ofstream yieldsFile(yieldsFileName.c_str());

  yieldsFile << "------------------------" << std::endl;
  yieldsFile << "Yields @ " << lumi_fb << " fb-1" << std::endl;
  yieldsFile << "------------------------" << std::endl;

  yieldsFile << std::endl;
  yieldsFile << "                    (mm)m   \t(mm)e   \t(ee)m   \t(ee)e   \tTotal" << std::endl << std::endl;


  float s_mmm = 0.;
  float s_mme = 0.;
  float s_eem = 0.;
  float s_eee = 0.;
  float s = 0.;

  float b_mmm = 0.;
  float b_mme = 0.;
  float b_eem = 0.;
  float b_eee = 0.;
  float b  = 0.;


  for( unsigned i=0; i<db->get_mcFiles().size(); ++i) {

    // reverse order:
    int iMC = db->get_mcFiles().size()-i-1;

    TTree* tree_mc = (TTree*)(db->get_mcFile(iMC).file->Get("tree_passedEvents"));

    TH1D* h1_mc_mmm = new TH1D("mc_mmm", "", 100, 0., 10000.);
    TH1D* h1_mc_mme = new TH1D("mc_mme", "", 100, 0., 10000.);
    TH1D* h1_mc_eem = new TH1D("mc_eem", "", 100, 0., 10000.);
    TH1D* h1_mc_eee = new TH1D("mc_eee", "", 100, 0., 10000.);

    tree_mc->Project("mc_mmm", "ptZll", sel_mmm.c_str());
    tree_mc->Project("mc_mme", "ptZll", sel_mme.c_str());
    tree_mc->Project("mc_eem", "ptZll", sel_eem.c_str());
    tree_mc->Project("mc_eee", "ptZll", sel_eee.c_str());

    float mmm = lumi_fb*1000.*h1_mc_mmm->Integral();
    float mme = lumi_fb*1000.*h1_mc_mme->Integral();
    float eem = lumi_fb*1000.*h1_mc_eem->Integral();
    float eee = lumi_fb*1000.*h1_mc_eee->Integral();
    float total = mmm + mme + eem + eee;

    char hname[100];
    sprintf( hname, "yields_mc_%d", iMC);
    TH1D* h1_yields_mc = new TH1D(hname, "", 4, 0., 4.);
    h1_yields_mc->SetBinContent( 1, mmm );
    h1_yields_mc->SetBinContent( 2, mme );
    h1_yields_mc->SetBinContent( 3, eem );
    h1_yields_mc->SetBinContent( 4, eee );

    h1_yields_mc->SetFillColor( db->get_mcFile(iMC).fillColor );

    vh1_yields_mc.push_back( (TH1D*)h1_yields_mc );

    stackMC->Add(h1_yields_mc, "HISTO");



    if(  db->get_mcFiles()[iMC].legendName=="t#bar{t} + Z" ) {

      s_mmm += mmm;
      s_mme += mme;
      s_eem += eem;
      s_eee += eee;
      s += total;

    } else {

      yieldsFile << db->get_mcFiles()[iMC].legendName;
      for( unsigned ichar=0; ichar<20-db->get_mcFiles()[iMC].legendName.size(); ++ichar ) yieldsFile << " ";
      yieldsFile << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", mmm, mme, eem, eee, total) << std::endl;

      b_mmm += mmm;
      b_mme += mme;
      b_eem += eem;
      b_eee += eee;
      b += total;

    }

    delete h1_mc_mmm;
    delete h1_mc_mme;
    delete h1_mc_eem;
    delete h1_mc_eee;
    
  }
    

  yieldsFile << "Total BG            " << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", b_mmm, b_mme, b_eem, b_eee, b) << std::endl;
  yieldsFile << std::endl;
  yieldsFile << "Signal              " << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", s_mmm, s_mme, s_eem, s_eee, s) << std::endl;
  yieldsFile << "s / b               " << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", s_mmm/b_mmm, s_mme/b_mme, s_eem/b_eem, s_eee/b_eee, s/b) << std::endl;
  yieldsFile << "s / sqrt(b)         " << Form("%.4f \t %.4f \t %.4f \t %.4f \t %.4f", s_mmm/sqrt(b_mmm), s_mme/sqrt(b_mme), s_eem/sqrt(b_eem), s_eee/sqrt(b_eee), s/sqrt(b)) << std::endl;

  yieldsFile.close();

 
  for( unsigned i=0; i<db->get_mcFiles().size(); ++i) {

    int inverseIndex = db->get_mcFiles().size()-i-1;
    if( vh1_yields_mc[inverseIndex]->Integral()>0 )
      legend->AddEntry( vh1_yields_mc[inverseIndex], db->get_mcFile(i).legendName.c_str(), "F" );

  } 






  float yMax = stackMC->GetMaximum();
  yMax *= 2.2;

  TH2D* h2_axes = new TH2D("axes", "", 4, 0., 4., 10, 0., yMax);
  h2_axes->GetXaxis()->SetLabelSize(0.085);
  h2_axes->GetXaxis()->SetBinLabel(1, "(#mu#mu)#mu");
  h2_axes->GetXaxis()->SetBinLabel(2, "(#mu#mu)e");
  h2_axes->GetXaxis()->SetBinLabel(3, "(ee)#mu");
  h2_axes->GetXaxis()->SetBinLabel(4, "(ee)e");
  h2_axes->SetYTitle("Events");


  TPaveText* label_sqrt = db->get_labelSqrt();

  TCanvas* c1 = new TCanvas("c1", "", 600, 600);
  c1->cd();
  h2_axes->Draw();
  stackMC->Draw("histo same");
  legend->Draw("same");
  label_sqrt->Draw("same");

  gPad->RedrawAxis();
  
  char canvasName[500];
  if( saveName!="" )
    sprintf( canvasName, "%s/channelYields_%s.eps", db->get_outputdir().c_str(), saveName.c_str() );
  else
    sprintf( canvasName, "%s/channelYields.eps", db->get_outputdir().c_str() );
  c1->SaveAs(canvasName);

  delete c1;
  delete h2_axes;

  for( unsigned i=0; i<vh1_yields_mc.size(); ++i ) 
    delete vh1_yields_mc[vh1_yields_mc.size()-i-1];

}
int main(int argc, char** argv){

  TString chfile;
  TString chfileref;
  TString DirectoryLast;
  TString labelData;
  TString labelRef;


  int ntrueargs = 0;
  bool logyFlag = true;
  bool normalize = false;

  for (int i=1; i<argc; ++i) {
      if (argv[i][0] == '-') {
            if (argv[i][1]=='l') logyFlag = false;
            else if (argv[i][1]=='b') gROOT->SetBatch();
            else if (argv[i][1]=='h') return printUsage();
            else if (argv[i][1]=='n') normalize=true;
            else if (argv[i][1]=='D') labelData = argv[i+1];
            else if (argv[i][1]=='R') labelRef= argv[i+1];

      } else {
            ntrueargs += 1;
            if (ntrueargs==1) chfile = argv[i];
            else if (ntrueargs==2) chfileref = argv[i];
            else if (ntrueargs==3) DirectoryLast = argv[i];
      }
  }

  if (ntrueargs<3) return printUsage();

  TRint* app = new TRint("CMS Root Application", 0, 0);

  TString cmssw_version = gSystem->Getenv("CMSSW_VERSION");
  TString chsample = "EWKMu";
  TString chtitle = chsample + " validation for " + cmssw_version;




  //TCanvas* c1 = new TCanvas("c1",chtitle.Data());
  TCanvas* c1 = new TCanvas("c1",chtitle.Data(),0,0,1024,768);
  c1->SetFillColor(0);
  TPaveLabel* paveTitle = new TPaveLabel(0.1,0.93,0.9,0.99, chtitle.Data());
  paveTitle->Draw();
  paveTitle->SetFillColor(0);
  gStyle->SetOptLogy(logyFlag);
  gStyle->SetPadGridX(true);
  gStyle->SetPadGridY(true);
  gStyle->SetOptStat(0);
//  gStyle->SetFillColor(0);

  TPad* pad[4];
  pad[0] = new TPad("pad_tl","The top-left pad",0.01,0.48,0.49,0.92);
  pad[0]->SetFillColor(0); 
  pad[1] = new TPad("pad_tr","The top-right pad",0.51,0.48,0.99,0.92); 
  pad[1]->SetFillColor(0);
  pad[2] = new TPad("pad_bl","The bottom-left pad",0.01,0.01,0.49,0.46); 
  pad[2]->SetFillColor(0);
  pad[3] = new TPad("pad_br","The bottom-right pad",0.51,0.01,0.99,0.46); 
  pad[3]->SetFillColor(0);

  for (unsigned int i=0; i<4; ++i) pad[i]->Draw();
                                                                                
  TLegend* leg = new TLegend(0.6041667,0.7487715,0.9861111,0.9576167);
  leg->SetFillColor(0);
  TFile* input_file = new TFile(chfile.Data(),"READONLY");
  TFile* input_fileref = new TFile(chfileref.Data(),"READONLY");
  bool first_plots_done = false;

  TString directory = DirectoryLast + "/BeforeCuts";

  TDirectory* dir_before = input_file->GetDirectory(directory);
  TDirectory* dirref_before = input_fileref->GetDirectory(directory);
  TList* list_before = dir_before->GetListOfKeys();
  list_before->Print();

  unsigned int list_before_size = list_before->GetSize();
  TString auxTitle = chtitle + ": BEFORE CUTS";
  for (unsigned int i=0; i<list_before_size; i+=4) {
      if (first_plots_done==true) c1->DrawClone();
      paveTitle->SetLabel(auxTitle.Data());
      for (unsigned int j=0; j<4; ++j) {
            pad[j]->cd(); 
            pad[j]->Clear(); 
            if ((i+j)>=list_before_size) continue;

            TH1D* h1 = (TH1D*)dir_before->Get(list_before->At(i+j)->GetName()); 
//            h1->SetLineColor(kBlue);
//            h1->SetMarkerColor(kBlue);
            h1->SetMarkerStyle(21);
            h1->SetLineStyle(1);
            h1->SetLineWidth(3);
            h1->SetTitleSize(0.05,"X");
            h1->SetTitleSize(0.05,"Y");
            TString title=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetTitle();
            TString name=(TString)dir_before->Get(list_before->At(i+j)->GetName())->GetName(); 
            TString nameD =name+"_MC";
            h1->SetXTitle(title);
            h1->SetName(nameD);

            h1->SetYTitle("");
            h1->SetTitle(""); 
            h1->SetTitleOffset(0.85,"X");

            TH1D* hr = (TH1D*)dirref_before->Get(list_before->At(i+j)->GetName()); 
            hr->SetLineColor(kPink-4);
//            hr->SetLineStyle(2);
            hr->SetLineWidth(3);
            hr->SetTitleSize(0.05,"X");
            hr->SetTitleSize(0.05,"Y");
            hr->SetFillColor(kPink-4);
            hr->SetFillStyle(3001);
            hr->SetXTitle(title);
            TString nameMC =name+"_Data";
            h1->SetName(nameMC);

            hr->SetYTitle("");
            hr->SetTitle("");
            hr->SetTitleOffset(0.85,"X");



            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
            else{hr->Draw("hist");}
            h1->Draw("sames,p,E");
            
            int max1=h1->GetMaximum();
            int maxr=hr->GetMaximum();
            if(!normalize){
            if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);}
            else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);}
            }
            else if (normalize){
            hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2);
            }


            leg->Clear();
            leg->AddEntry(h1,labelData.Data(),"Lp");
            leg->AddEntry(hr,labelRef.Data() ,"f");

            leg->Draw();




      }
      first_plots_done = true;
      c1->Modified();
      c1->Update();
      char chplot[80];
      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
      sprintf(chplot,"%sValidation_%s_BEFORECUTS_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
  }

  TString directory2 = DirectoryLast + "/LastCut";

  TDirectory* dir_lastcut = input_file->GetDirectory(directory2);
  TDirectory* dirref_lastcut = input_fileref->GetDirectory(directory2);
  TList* list_lastcut = dir_lastcut->GetListOfKeys();
  list_lastcut->Print();

  unsigned int list_lastcut_size = list_lastcut->GetSize();
  auxTitle = chtitle + ": AFTER N-1 CUTS";
  for (unsigned int i=0; i<list_lastcut_size; i+=4) {
      if (first_plots_done==true) c1->DrawClone();
      paveTitle->SetLabel(auxTitle.Data());
      for (unsigned int j=0; j<4; ++j) {
            pad[j]->cd(); 
            pad[j]->Clear(); 
            if ((i+j)>=list_lastcut_size) continue;

            TH1D* h1 = (TH1D*)dir_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
//            h1->SetLineColor(kBlue);
//            h1->SetMarkerColor(kBlue);
            h1->SetMarkerStyle(21);
            h1->SetLineWidth(3);
            h1->SetTitleSize(0.05,"X");
            h1->SetTitleSize(0.05,"Y");
            TString name=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetName();
            TString title=(TString)dir_lastcut->Get(list_lastcut->At(i+j)->GetName())->GetTitle();
            TString nameD=name+"_Data";
            h1->SetXTitle(title); 
            h1->SetName(nameD);
            h1->SetYTitle("");
            h1->SetTitle(""); 
            h1->SetTitleOffset(0.85,"X");

            TH1D* hr = (TH1D*)dirref_lastcut->Get(list_lastcut->At(i+j)->GetName()); 
            hr->SetLineColor(kAzure+5);
//            hr->SetLineStyle(2);
            hr->SetLineWidth(3);
            hr->SetTitleSize(0.05,"X");
            hr->SetTitleSize(0.05,"Y");
            hr->SetFillColor(kAzure+5);
            hr->SetFillStyle(3001);
            hr->SetXTitle(title);
            TString nameMC=name+"_Data";
            h1->SetName(nameMC);
            hr->SetYTitle("");
            hr->SetTitle("");
            hr->SetTitleOffset(0.85,"X");


            if(normalize) {hr->DrawNormalized("hist",h1->Integral());}
            else{hr->Draw("hist");}
            h1->Draw("sames,p,E");

            int max1=h1->GetMaximum();
            int maxr=hr->GetMaximum();
            if(!normalize){
            if(max1 >= maxr) { hr->SetMaximum(max1*1.2); h1->SetMaximum(max1*1.2);}
            else {hr->SetMaximum(maxr*1.2); h1->SetMaximum(maxr*1.2);}
            }
            else if (normalize){
            hr->GetYaxis()->SetRangeUser(h1->GetMinimum()*0.1,max1*1.2);
            }
            

            leg->Clear();
            leg->AddEntry(h1,labelData.Data(),"lp");
            leg->AddEntry(hr,labelRef.Data(),"f");
            leg->Draw();
      }
      first_plots_done = true;
      c1->Modified();
      c1->Update();
      char chplot[80];
      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.root",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
      sprintf(chplot,"%sValidation_%s_LASTCUT_%d.gif",chsample.Data(),cmssw_version.Data(),i/4);
      c1->SaveAs(chplot);
  }

  if (!gROOT->IsBatch()) app->Run();

  return 0;
}
示例#4
0
void MakeSystPlot(const TString& channel, TFile * input, RooWorkspace * ws, const RooArgList * obs, 
                  const Int_t p, const Int_t up, const Int_t down)
{
    TString pdfname = g_pdfname;
    pdfname.ReplaceAll("$CHANNEL", channel);

    const TString& process = g_processes[p];
    TString systUp = g_systematics[up];
    systUp.ReplaceAll("$CHANNEL", channel);
    systUp.ReplaceAll("$PROCESS", process);
    
    TString systDown = g_systematics[down];
    systDown.ReplaceAll("$CHANNEL", channel);
    systDown.ReplaceAll("$PROCESS", process);

    if (process != "Wj0b" && process != "Wj1b" && process != "Wj2b") {
        if (systUp.Contains("WJModel") || systDown.Contains("WJModel") || systUp.Contains("WJSlope") || systDown.Contains("WJSlope"))
            return;
    }

    if (process != "Zj0b" && process != "Zj1b" && process != "Zj2b") {
        if (systUp.Contains("ZJModel") || systDown.Contains("ZJModel") || systUp.Contains("ZJSlope") || systDown.Contains("ZJSlope"))
            return;
    }
    
    if (process != "TT") {
        if (systUp.Contains("TTModel") || systDown.Contains("TTModel"))
            return;
    }
    
    TH1F * h = (TH1F *) input->Get(channel + "/" + process);
    TH1F * hUp = (TH1F *) input->Get(channel + "/" + process + "_" + systUp);
    TH1F * hDown = (TH1F *) input->Get(channel + "/" + process + "_" + systDown);
    if ((h->Integral() > 0. && hUp->Integral() <= 0.) || h->Integral() <= 0.) {
        TString clonename = hUp->GetName();
        delete hUp;
        hUp = (TH1F*) h->Clone(clonename);
    }
    if ((h->Integral() > 0. && hDown->Integral() <= 0.) || h->Integral() <= 0.) {
        TString clonename = hDown->GetName();
        delete hDown;
        hDown = (TH1F*) h->Clone(clonename);
    }
    if (process == "WH" || process == "ZH" || process == "VH") {
        if (systUp.Contains("eff_b"))
            systUp.ReplaceAll("eff_b", "eff_b_SIG");
        if (systDown.Contains("eff_b"))
            systDown.ReplaceAll("eff_b", "eff_b_SIG");
    }
    RooDataHist * dhUp = new RooDataHist(process + "_" + systUp, "", *obs, hUp);
    ws->import(*dhUp);
    RooDataHist * dhDown = new RooDataHist(process + "_" + systDown, "", *obs, hDown);
    ws->import(*dhDown);
    
    h->SetStats(0);
    h->SetTitle("; BDT");
    h->SetLineColor(1);
    h->SetLineWidth(2);
    h->SetFillColor(0);
    h->SetMarkerStyle(20);
    h->SetMinimum(0.01);
    h->GetXaxis()->CenterTitle();
    
    hUp->SetLineColor(g_upcol);
    hUp->SetLineWidth(2);
    hUp->SetFillColor(0);
    
    hDown->SetLineColor(g_downcol);
    hDown->SetLineWidth(2);
    hDown->SetFillColor(0);
    
    h->Draw("e1");
    hUp->Draw("hist same");
    hDown->Draw("hist same");
    h->Draw("e1 same");
    
    TLegend * leg = new TLegend(0.35, 0.20, 0.92, 0.35);
    leg->SetFillColor(0);
    leg->SetFillStyle(0);
    leg->SetLineColor(0);
    leg->SetShadowColor(0);
    leg->SetTextFont(62);
    //leg->SetTextSize(0.015);
    leg->AddEntry(h, process, "pl");
    leg->AddEntry(hUp, systUp, "l");
    leg->AddEntry(hDown, systDown, "l");
    leg->Draw();

    gPad->RedrawAxis();
    gPad->Modified();
    gPad->Update();
    gPad->Print(pdfname);
    
    delete dhUp;
    delete dhDown;
    delete leg;
    
    return;
}
void DarkSusy_mH_125_mGammaD_2000_cT_100_LHE_gammaD_M()
{
//=========Macro generated from canvas: cnv/cnv
//=========  (Sun May 24 15:18:26 2015) by ROOT version6.02/05
   TCanvas *cnv = new TCanvas("cnv", "cnv",1,1,904,904);
   gStyle->SetOptFit(1);
   gStyle->SetOptStat(0);
   gStyle->SetOptTitle(0);
   cnv->SetHighLightColor(2);
   cnv->Range(-1.526695,-0.2275,1.571513,1.5225);
   cnv->SetFillColor(0);
   cnv->SetBorderMode(0);
   cnv->SetBorderSize(2);
   cnv->SetLogx();
   cnv->SetTickx(1);
   cnv->SetTicky(1);
   cnv->SetLeftMargin(0.17);
   cnv->SetRightMargin(0.03);
   cnv->SetTopMargin(0.07);
   cnv->SetBottomMargin(0.13);
   cnv->SetFrameFillStyle(0);
   cnv->SetFrameBorderMode(0);
   cnv->SetFrameFillStyle(0);
   cnv->SetFrameBorderMode(0);
   
   TH1F *h_gammaD_1_M_dummy86 = new TH1F("h_gammaD_1_M_dummy86","h_gammaD_1_M_dummy",303,0.1,30.1);
   h_gammaD_1_M_dummy86->SetMaximum(1.4);
   h_gammaD_1_M_dummy86->SetLineStyle(0);
   h_gammaD_1_M_dummy86->SetMarkerStyle(20);
   h_gammaD_1_M_dummy86->GetXaxis()->SetTitle("Mass of #gamma_{D} [GeV]");
   h_gammaD_1_M_dummy86->GetXaxis()->SetLabelFont(42);
   h_gammaD_1_M_dummy86->GetXaxis()->SetLabelOffset(0.007);
   h_gammaD_1_M_dummy86->GetXaxis()->SetTitleSize(0.06);
   h_gammaD_1_M_dummy86->GetXaxis()->SetTitleOffset(0.95);
   h_gammaD_1_M_dummy86->GetXaxis()->SetTitleFont(42);
   h_gammaD_1_M_dummy86->GetYaxis()->SetTitle("Fraction of events / 0.1 GeV");
   h_gammaD_1_M_dummy86->GetYaxis()->SetLabelFont(42);
   h_gammaD_1_M_dummy86->GetYaxis()->SetLabelOffset(0.007);
   h_gammaD_1_M_dummy86->GetYaxis()->SetTitleSize(0.06);
   h_gammaD_1_M_dummy86->GetYaxis()->SetTitleOffset(1.35);
   h_gammaD_1_M_dummy86->GetYaxis()->SetTitleFont(42);
   h_gammaD_1_M_dummy86->GetZaxis()->SetLabelFont(42);
   h_gammaD_1_M_dummy86->GetZaxis()->SetLabelOffset(0.007);
   h_gammaD_1_M_dummy86->GetZaxis()->SetTitleSize(0.06);
   h_gammaD_1_M_dummy86->GetZaxis()->SetTitleFont(42);
   h_gammaD_1_M_dummy86->Draw("");
   
   TH1F *h_gammaD_1_M87 = new TH1F("h_gammaD_1_M87","h_gammaD_1_M",303,0.1,30.1);
   h_gammaD_1_M87->SetBinContent(201,1);
   h_gammaD_1_M87->SetBinError(201,0.002500016);
   h_gammaD_1_M87->SetEntries(159998);
   h_gammaD_1_M87->SetDirectory(0);

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha
   ci = TColor::GetColor("#0000ff");
   h_gammaD_1_M87->SetLineColor(ci);
   h_gammaD_1_M87->SetLineWidth(2);
   h_gammaD_1_M87->SetMarkerStyle(20);
   h_gammaD_1_M87->GetXaxis()->SetLabelFont(42);
   h_gammaD_1_M87->GetXaxis()->SetLabelOffset(0.007);
   h_gammaD_1_M87->GetXaxis()->SetTitleSize(0.06);
   h_gammaD_1_M87->GetXaxis()->SetTitleOffset(0.95);
   h_gammaD_1_M87->GetXaxis()->SetTitleFont(42);
   h_gammaD_1_M87->GetYaxis()->SetLabelFont(42);
   h_gammaD_1_M87->GetYaxis()->SetLabelOffset(0.007);
   h_gammaD_1_M87->GetYaxis()->SetTitleSize(0.06);
   h_gammaD_1_M87->GetYaxis()->SetTitleOffset(1.3);
   h_gammaD_1_M87->GetYaxis()->SetTitleFont(42);
   h_gammaD_1_M87->GetZaxis()->SetLabelFont(42);
   h_gammaD_1_M87->GetZaxis()->SetLabelOffset(0.007);
   h_gammaD_1_M87->GetZaxis()->SetTitleSize(0.06);
   h_gammaD_1_M87->GetZaxis()->SetTitleFont(42);
   h_gammaD_1_M87->Draw("SAMEHIST");
   
   TLegend *leg = new TLegend(0.4566667,0.82,0.7822222,0.9066667,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetTextSize(0.02777778);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   TLegendEntry *entry=leg->AddEntry("NULL","#splitline{pp #rightarrow h #rightarrow 2n_{1} #rightarrow 2n_{D} + 2 #gamma_{D} #rightarrow 2n_{D} + 4#mu}{#splitline{m_{h} = 125 GeV, m_{n_{1}} = 50 GeV, m_{n_{D}} = 1 GeV}{m_{#gamma_{D}} = 20 GeV, c#tau_{#gamma_{D}} = 100 mm}}","h");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   
   leg = new TLegend(0.17,0.935,0.97,1,NULL,"brNDC");
   leg->SetBorderSize(0);
   leg->SetTextAlign(22);
   leg->SetTextSize(0.045);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(0);
   entry=leg->AddEntry("NULL","CMS Simulation (LHE) 14 TeV","h");
   entry->SetLineColor(1);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);
   entry->SetMarkerColor(1);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   cnv->Modified();
   cnv->cd();
   cnv->SetSelected(cnv);
}
void showFunctions1d(std::vector<TF1*>& functions, const std::vector<std::string>& legendEntries,
		     const TString& xAxisTitle, double yMin, double yMax, const TString& yAxisTitle, 
		     const std::string& outputFileName)
{
  assert(functions.size() == legendEntries.size());

  TCanvas* canvas = new TCanvas("canvas", "canvas", 800, 600);
  canvas->SetFillColor(10);
  canvas->SetBorderSize(2);
  
  canvas->SetLeftMargin(0.12);
  canvas->SetBottomMargin(0.12);

  assert(functions.size() > 0);
  TF1* refFunction = functions[0];

  TH1* dummyHistogram = new TH1F("dummyHistogram", "dummyHistogram", 10, refFunction->GetXmin(), refFunction->GetXmax());
  dummyHistogram->SetStats(false);
  dummyHistogram->SetTitle("");
  dummyHistogram->SetMinimum(-TMath::Log(yMax));
  dummyHistogram->SetMaximum(-TMath::Log(yMax) + 5.);
  
  TAxis* xAxis = dummyHistogram->GetXaxis();
  xAxis->SetTitle(xAxisTitle.Data());
  xAxis->SetTitleOffset(1.15);

  TAxis* yAxis = dummyHistogram->GetYaxis();
  yAxis->SetTitle(Form("-log(%s)", yAxisTitle.Data()));
  yAxis->SetTitleOffset(1.30);

  dummyHistogram->Draw("axis");

  int colors[] = { 1, 2, 3, 4, 5, 6, 7, 15 };
  int numFunctions = functions.size();
  if ( numFunctions > 8 ) {
    std::cerr << "<showFunctions1d>:" << std::endl;
    std::cerr << "Number of functions must not exceed 8 !!" << std::endl;
    assert(0);
  }
  
  for ( int iFunction = 0; iFunction < numFunctions; ++iFunction ) {
    TF1* function = functions[iFunction];
    function->SetLineColor(colors[iFunction]);
    function->SetLineWidth(2);
    function->Draw("same");
  }

  TLegend* legend = new TLegend(0.68, 0.89 - (0.03 + 0.040*numFunctions), 0.89, 0.89, "", "brNDC"); 
  legend->SetBorderSize(0);
  legend->SetFillColor(0);
  legend->SetTextSize(0.035);
  for ( int iFunction = 0; iFunction < numFunctions; ++iFunction ) {
    TF1* function = functions[iFunction];
    const std::string& legendEntry = legendEntries[iFunction];
    legend->AddEntry(function, legendEntry.data(), "l");
  }
  legend->Draw();

  canvas->Update();
  size_t idx = outputFileName.find_last_of('.');
  std::string outputFileName_plot = std::string(outputFileName, 0, idx);
  if ( idx != std::string::npos ) canvas->Print(std::string(outputFileName_plot).append(std::string(outputFileName, idx)).data());
  canvas->Print(std::string(outputFileName_plot).append(".png").data());
  canvas->Print(std::string(outputFileName_plot).append(".pdf").data());

  delete dummyHistogram;
  delete legend;
  delete canvas;
}
TCanvas* overlay_Merged_RecoSmeared(const vector<string>& folders, 
								const hist_t& h
								)
{

	TLegend *leg  = new TLegend(0.6,0.65,0.9,0.9);
	leg->SetTextFont(42);
	vector<TH1*> hists;
	
	vector<string> jetcoll;
	jetcoll.push_back("reco");
	jetcoll.push_back("gen");
	jetcoll.push_back("smeared");

	stringstream title;
	const string njets("3-5");
	//const string eta("2.5");
	const string eta("5.0");
	title << njets
			<< " Jets, MHT from Jets with P_{T}>30 GeV, |#eta |<" 
			<< eta << ", L = 10 fb^{-1}" << ";" << h.title ;

	for (unsigned j=0; j< jetcoll.size(); ++j)
	{
		TH1* Hist = 0;
		for (unsigned i = 0; i < folders.size(); ++i)
		{
			stringstream histname;
			histname << folders.at(i) << "/" << jetcoll.at(j) << h.name;
			cout << __LINE__ << ": Looking for hist: " << histname.str().c_str() << endl;
			TH1* htemp = GetHist(histname.str());
			
			if (Hist == 0) Hist = htemp;
			else Hist->Add(htemp);
		}
		
		Hist->Rebin(h.rebin);
		Hist->SetTitle(title.str().c_str());
		Hist->SetMarkerStyle(20+j);
		Hist->SetLineWidth(2);
		Hist->SetStats(0);

		stringstream legname;
		if (j==0) 
		{
			legname << "Reco"; 
		} else if (j==1) 
		{
			legname << "Gen"; 
			Hist->SetLineColor(kBlue);
			Hist->SetMarkerColor(kBlue);
		} else if (j==2)
		{
			legname << "Smeared"; 
			Hist->SetLineColor(kRed);
			Hist->SetMarkerColor(kRed);
		}

		const double sum = Hist->Integral(); 
		legname << " (" << sum << ")";
		if (j!=1) leg->AddEntry(Hist, legname.str().c_str());

		hists.push_back(Hist);

	} //end jetcoll
	
	TH1* ratio = dynamic_cast<TH1*> (hists.at(2)->Clone("ratio"));
	ratio->GetYaxis()->SetTitle("Smeared/Reco");
	ratio->SetTitle("");
	ratio->Divide(hists.at(0));
	ratio->GetYaxis()->SetRangeUser(-0.01,2.01);
	//ratio->SetTickLength (+0.01,"Y");

   //TCanvas *c1 = new TCanvas("c1", "c1",15,60,550,600);
   TCanvas *c1 = new TCanvas("c1");
   c1->Range(0,0,1,1);
   c1->SetBorderSize(2);
   c1->SetFrameFillColor(0);
  
// ------------>Primitives in pad: c1_1
   TPad *c1_1 = new TPad("c1_1", "c1_1",0.01,0.30,0.99,0.99);
   c1_1->Draw();
   c1_1->cd();
   c1_1->SetBorderSize(2);
   c1_1->SetTickx(1);
   c1_1->SetTicky(1);
   c1_1->SetTopMargin(0.1);
   c1_1->SetBottomMargin(0.0);
   //c1_1->SetFrameFillColor(3);
	c1_1->SetLogy();
   
	hists.at(0)->GetYaxis()->CenterTitle(1);
	hists.at(0)->SetLabelFont(42,"XYZ");
	hists.at(0)->SetTitleFont(42,"XYZ");
	hists.at(0)->GetYaxis()->SetTitleOffset(0.8);
	hists.at(0)->SetLabelSize(0.05,"XYZ");
	hists.at(0)->SetTitleSize(0.06,"XYZ");
   hists.at(0)->Draw("P");
   hists.at(2)->Draw("same P");
	leg->Draw();

   c1_1->Modified();
   c1->cd();
  
// ------------>Primitives in pad: c1_2
   TPad *c1_2 = new TPad("c1_2", "c1_2",0.01,0.01,0.99,0.30);
   c1_2->Draw();
   c1_2->cd();
   c1_2->SetBorderSize(2);
   c1_2->SetTickx(1);
   c1_2->SetTicky(1);
   c1_2->SetTopMargin(0.0);
   c1_2->SetBottomMargin(0.24);
   c1_2->SetFrameFillColor(0);
	c1_2->SetGridx();
	c1_2->SetGridy();
   
	ratio->GetYaxis()->SetTitleOffset(0.4);
	ratio->GetXaxis()->SetTitleOffset(0.9);
	ratio->GetYaxis()->CenterTitle(1);
	ratio->GetXaxis()->CenterTitle(1);
	ratio->SetLabelSize(0.125,"XYZ");
	ratio->SetTitleSize(0.125,"XYZ");
//	ratio->SetLabelFont(labelfont,"XYZ");
//	ratio->SetTitleFont(titlefont,"XYZ");
   ratio->GetXaxis()->SetTickLength(0.07);
   ratio->Draw("");
   
   c1_2->Modified();
   c1->cd();
   //c1->Modified();
   //c1->cd();
   //c1->SetSelected(c1);
	return c1;

}
vector <double> finalize2012_gammaJets(double int_exp_2012_30, double int_exp_2012_50, double int_exp_2012_75, double int_exp_2012_90, double pt1min_30=30, double pt1min_50=50, double pt1min_75=75, double pt1min_90=90, double pt1max_30=30, double pt1max_50=50, double pt1max_75=75, double pt1max_90=90, int eb = 1, int r9 = 1, string variableMC = "massgg", string variableData = "massgg", int nbin = 200, double min = 90, double max = 190, string axis = "m(#gamma#gamma)[GeV]"){
  
  gROOT->SetStyle("Plain");
  gStyle->SetPalette(1);
  gStyle->SetOptStat(1111111);  
  gStyle->SetOptFit(111110); 
  gStyle->SetOptFile(1); 
  gStyle->SetMarkerStyle(20);
  gStyle->SetMarkerSize(.3);
  gStyle->SetMarkerColor(1);
  
  TCanvas* c0 = new TCanvas("c0"," ",200,10,500,500);
  c0->Clear();
  
  // input files
  string mcnames[16];
  mcnames[0]  = "QCD, 20-30";
  mcnames[1]  = "QCD, 30-80";
  mcnames[2]  = "QCD, 80-170";
  mcnames[3]  = "QCD, 170-250";
  mcnames[4]  = "QCD, 250-350";
  mcnames[5]  = "QCD, >350";
  mcnames[6]  = "gjet, 0-15";
  mcnames[7]  = "gjet, 15-30";
  mcnames[8]  = "gjet, 30-50";
  mcnames[9]  = "gjet, 50-80";
  mcnames[10] = "gjet, 80-120";
  mcnames[11] = "gjet, 120-170";
  mcnames[12] = "gjet, 170-300";
  // 
  mcnames[13] = "gjet, 470-800";
  mcnames[14] = "gjet, 800-1400";
  mcnames[15] = "gjet, 1400-1800";

  TFile* mc_2012[16];            // [16] = MC samples

  TString redntpDir= "/xrootdfs/cms/local/crovelli/GammaJets/reduced";

  // full 2012                                     
  TFile* data = TFile::Open(redntpDir+"/redntp.53xv2_data.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/all2012.root");
  
  // mc signal and backgrounds   
  if( int_exp_2012_30 > 0 ){
    
    // QCD samples
    mc_2012[0] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_QCD_Pt_20_30_EMEnriched_TuneZ2star_8TeV_pythia6.root");
    mc_2012[1] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_QCD_Pt_30_80_EMEnriched_TuneZ2star_8TeV_pythia6.root");
    mc_2012[2] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_QCD_Pt_80_170_EMEnriched_TuneZ2star_8TeV_pythia6.root");
    mc_2012[3] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_QCD_Pt_170_250_EMEnriched_TuneZ2star_8TeV_pythia6.root");
    mc_2012[4] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_QCD_Pt_250_350_EMEnriched_TuneZ2star_8TeV_pythia6.root");
    mc_2012[5] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_QCD_Pt_350_EMEnriched_TuneZ2star_8TeV_pythia6.root");
    // gjet samples 
    mc_2012[6]  = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-0to15_TuneZ2star_8TeV_pythia6.root");
    mc_2012[7]  = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-15to30_TuneZ2star_8TeV_pythia6.root");
    mc_2012[8]  = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-30to50_TuneZ2star_8TeV_pythia6.root");
    mc_2012[9]  = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-50to80_TuneZ2star_8TeV_pythia6.root");
    mc_2012[10] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-80to120_TuneZ2star_8TeV_pythia6.root");
    mc_2012[11] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-120to170_TuneZ2star_8TeV_pythia6.root");
    mc_2012[12] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-170to300_TuneZ2star_8TeV_pythia6.root");
    mc_2012[13] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-470to800_TuneZ2star_8TeV_pythia6.root");
    mc_2012[14] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-800to1400_TuneZ2star_8TeV_pythia6.root");
    mc_2012[15] = TFile::Open(redntpDir+"/redntp.53xv2.cicpfloose.noCorrections.GammaJets_newNtuples_v5/merged/redntp_G_Pt-1400to1800_TuneZ2star_8TeV_pythia6.root");
  }
  
  // k factors 
  double kfactorqcd    = 1.;   
  double kfactorgamjet = 1.3;           //  chiara: still valid?

  // cross sections at 8 TeV - all from PREP
  double cross_mc[16];
  cross_mc[0]  = 288600000 * 0.0101 * kfactorqcd;         
  cross_mc[1]  = 74330000 * 0.0621 * kfactorqcd;         
  cross_mc[2]  = 1191000 * 0.1539 * kfactorqcd;         
  cross_mc[3]  = 30990 * 0.148 * kfactorqcd;         
  cross_mc[4]  = 4250 * 0.131 * kfactorqcd;         
  cross_mc[5]  = 810 * 0.11 * kfactorqcd;          
  cross_mc[6]  = 90601456 * kfactorgamjet;          
  cross_mc[7]  = 200061.7 * kfactorgamjet;          
  cross_mc[8]  = 19931.62 * kfactorgamjet;          
  cross_mc[9]  = 3322.309 * kfactorgamjet;          
  cross_mc[10] = 558.2865 * kfactorgamjet;          
  cross_mc[11] = 108.0068 * kfactorgamjet;          
  cross_mc[12] = 30.12207 * kfactorgamjet;          
  cross_mc[13] = 0.2119244 * kfactorgamjet;          
  cross_mc[14] = 0.007077847 * kfactorgamjet;          
  cross_mc[15] = 4.510327 * 0.00001 * kfactorgamjet;          

  // getting the number of original events in each sample (processed with CMSSW)
  int n_mc_2012[16];   
  for(int i=0; i<16; i++){
    n_mc_2012[i] = 0;
    if(int_exp_2012_30>0) n_mc_2012[i] = ((TH1D*)mc_2012[i]->Get("ptphotgen1"))->GetEntries();  
  }

  // setting the scaling factor to actual lumi 
  double scale_mc_2012_30[16];
  double scale_mc_2012_50[16];
  double scale_mc_2012_75[16];
  double scale_mc_2012_90[16];

  for(int i=0; i<16; i++){
    scale_mc_2012_30[i] = 0; 
    scale_mc_2012_50[i] = 0; 
    scale_mc_2012_75[i] = 0; 
    scale_mc_2012_90[i] = 0; 
    if(int_exp_2012_30>0) scale_mc_2012_30[i] = cross_mc[i] * int_exp_2012_30 / n_mc_2012[i];
    if(int_exp_2012_50>0) scale_mc_2012_50[i] = cross_mc[i] * int_exp_2012_50 / n_mc_2012[i];
    if(int_exp_2012_75>0) scale_mc_2012_75[i] = cross_mc[i] * int_exp_2012_75 / n_mc_2012[i];
    if(int_exp_2012_90>0) scale_mc_2012_90[i] = cross_mc[i] * int_exp_2012_90 / n_mc_2012[i];
  }

  // char for output name
  char name[1000];
  
  // output root file
  sprintf(name,"results_gammaJ/histo.root");
  TFile * hOutputFile = new TFile(name, "RECREATE" ) ;

  // histograms needed by the machinery
  TH1D* vardata_30 = new TH1D("vardata_30", "vardata_30", nbin,min,max);
  TH1D* vardata_50 = new TH1D("vardata_50", "vardata_50", nbin,min,max);
  TH1D* vardata_75 = new TH1D("vardata_75", "vardata_75", nbin,min,max);
  TH1D* vardata_90 = new TH1D("vardata_90", "vardata_90", nbin,min,max);

  vardata_30->Sumw2();
  vardata_50->Sumw2();
  vardata_75->Sumw2();
  vardata_90->Sumw2();

  TH1D* var_mc_2012_30[16];     // 16 = MC samples we have 
  TH1D* var_mc_2012_50[16];     // 16 = MC samples we have 
  TH1D* var_mc_2012_75[16];     // 16 = MC samples we have 
  TH1D* var_mc_2012_90[16];     // 16 = MC samples we have 

  TH1D* var_30[2];              // 2  = number of species
  TH1D* var_50[2];              // 2  = number of species
  TH1D* var_75[2];              // 2  = number of species
  TH1D* var_90[2];              // 2  = number of species

  for (int i=0; i<2; i++) {
    sprintf(name,"%s%d","var_30",i);
    var_30[i] = new TH1D(name,name,nbin,min,max);
    var_30[i]->Sumw2();          
    sprintf(name,"%s%d","var_50",i);
    var_50[i] = new TH1D(name,name,nbin,min,max);
    var_50[i]->Sumw2();          
    sprintf(name,"%s%d","var_75",i);
    var_75[i] = new TH1D(name,name,nbin,min,max);
    var_75[i]->Sumw2();          
    sprintf(name,"%s%d","var_90",i);
    var_90[i] = new TH1D(name,name,nbin,min,max);
    var_90[i]->Sumw2();          
 }

  for (int i=0; i<16; i++) {
    sprintf(name,"%s%d","var_mc_2012_30_",i);
    var_mc_2012_30[i] = new TH1D(name,name,nbin,min,max);
    var_mc_2012_30[i]->Sumw2();  
    sprintf(name,"%s%d","var_mc_2012_50_",i);
    var_mc_2012_50[i] = new TH1D(name,name,nbin,min,max);
    var_mc_2012_50[i]->Sumw2();  
    sprintf(name,"%s%d","var_mc_2012_75_",i);
    var_mc_2012_75[i] = new TH1D(name,name,nbin,min,max);
    var_mc_2012_75[i]->Sumw2();  
    sprintf(name,"%s%d","var_mc_2012_90_",i);
    var_mc_2012_90[i] = new TH1D(name,name,nbin,min,max);
    var_mc_2012_90[i]->Sumw2();  
  }




  // 1) HLT = 30
  cout << endl;
  cout << "------------------- HLT = 30 -------------------" << endl; 

  // creating the fillers and setting cuts: data
  fillPlot2012_gammaJets data_fill_30((TTree*)data->Get("AnaTree"));
  data_fill_30.Setcuts(pt1min_30,pt1max_30,eb,r9,30);  

  // analysis, data, HLT = 30 
  cout << "running over " << ((TTree*)data->Get("AnaTree"))->GetEntries("") << " data events for HLT 30" <<  endl;
  sprintf(name,"results_gammaJ/events_HLT30.root");
  data_fill_30.WriteRoot(name);
  vardata_30->Add(data_fill_30.Plot(variableData,"data", nbin, min, max, 100)); 
  std::cout << "Selected events on data " << vardata_30->GetEntries() << " with HLT = 30" << std::endl;

  // creating the fillers and setting cuts: MC, HLT = 30
  fillPlot2012_gammaJets* mc_2012_fill_30[16];
  for (int i=0; i<16; i++){
    if(int_exp_2012_30>0) mc_2012_fill_30[i] = new fillPlot2012_gammaJets((TTree*)mc_2012[i]->Get("AnaTree"));   
    if(int_exp_2012_30>0) mc_2012_fill_30[i]->Setcuts(pt1min_30,pt1max_30,eb,r9,30); 
    mc_2012_fill_30[i]->DoPuReweight();
  }

  // analysis, MC, HLT = 30 
  for (int i=0; i<16; i++){ 
    sprintf(name,"%s%s",mcnames[i].c_str()," 2012");
    if(int_exp_2012_30>0) {
      cout << "running over " << ((TTree*)mc_2012[i]->Get("AnaTree"))->GetEntries("") << " " << name << " events for HLT 30" <<  endl;   
      sprintf(name,"%s%s%s","results_gammaJ/events_",mcnames[i].c_str(),"_2012_HLT30.root");
      mc_2012_fill_30[i]->WriteRoot(name);             
      var_mc_2012_30[i]->Add( mc_2012_fill_30[i]->Plot(variableMC, name, nbin, min, max, i) );  
      std::cout << "Selected events on mc2012 " << name << " for HLT=30 " << var_mc_2012_30[i]->GetEntries() << std::endl;
    }
  }
  cout << endl;


  // 2) HLT = 50
  cout << endl;
  cout << "------------------- HLT = 50 -------------------" << endl; 

  // creating the fillers and setting cuts: data
  fillPlot2012_gammaJets data_fill_50((TTree*)data->Get("AnaTree"));
  data_fill_50.Setcuts(pt1min_50,pt1max_50,eb,r9,50);  

  // analysis, data, HLT = 50 
  cout << "running over " << ((TTree*)data->Get("AnaTree"))->GetEntries("") << " data events for HLT 50" <<  endl;
  sprintf(name,"results_gammaJ/events_HLT50.root");
  data_fill_50.WriteRoot(name);
  vardata_50->Add(data_fill_50.Plot(variableData,"data", nbin, min, max, 100)); 
  std::cout << "Selected events on data " << vardata_50->GetEntries() << " with HLT = 50" << std::endl;

  // creating the fillers and setting cuts: MC, HLT = 50
  fillPlot2012_gammaJets* mc_2012_fill_50[16];
  for (int i=0; i<16; i++){
    if(int_exp_2012_50>0) mc_2012_fill_50[i] = new fillPlot2012_gammaJets((TTree*)mc_2012[i]->Get("AnaTree"));   
    if(int_exp_2012_50>0) mc_2012_fill_50[i]->Setcuts(pt1min_50,pt1max_50,eb,r9,50); 
    mc_2012_fill_50[i]->DoPuReweight();
  }

  // analysis, MC, HLT = 50 
  for (int i=0; i<16; i++){ 
    sprintf(name,"%s%s",mcnames[i].c_str()," 2012");
    if(int_exp_2012_50>0) {
      cout << "running over " << ((TTree*)mc_2012[i]->Get("AnaTree"))->GetEntries("") << " " << name << " events for HLT 50" <<  endl;   
      sprintf(name,"%s%s%s","results_gammaJ/events_",mcnames[i].c_str(),"_2012_HLT50.root");
      mc_2012_fill_50[i]->WriteRoot(name);             
      var_mc_2012_50[i]->Add( mc_2012_fill_50[i]->Plot(variableMC, name, nbin, min, max, i) );  
      std::cout << "Selected events on mc2012 " << name << " for HLT=50 " << var_mc_2012_50[i]->GetEntries() << std::endl;
    }
  }
  cout << endl;


  // 1) HLT = 75
  cout << endl;
  cout << "------------------- HLT = 75 -------------------" << endl; 

  // creating the fillers and setting cuts: data
  fillPlot2012_gammaJets data_fill_75((TTree*)data->Get("AnaTree"));
  data_fill_75.Setcuts(pt1min_75,pt1max_75,eb,r9,75);  

  // analysis, data, HLT = 75 
  cout << "running over " << ((TTree*)data->Get("AnaTree"))->GetEntries("") << " data events for HLT 75" <<  endl;
  sprintf(name,"results_gammaJ/events_HLT75.root");
  data_fill_75.WriteRoot(name);
  vardata_75->Add(data_fill_75.Plot(variableData,"data", nbin, min, max, 100)); 
  std::cout << "Selected events on data " << vardata_75->GetEntries() << " with HLT = 75" << std::endl;

  // creating the fillers and setting cuts: MC, HLT = 75
  fillPlot2012_gammaJets* mc_2012_fill_75[16];
  for (int i=0; i<16; i++){
    if(int_exp_2012_75>0) mc_2012_fill_75[i] = new fillPlot2012_gammaJets((TTree*)mc_2012[i]->Get("AnaTree"));   
    if(int_exp_2012_75>0) mc_2012_fill_75[i]->Setcuts(pt1min_75,pt1max_75,eb,r9,75); 
    mc_2012_fill_75[i]->DoPuReweight();
  }

  // analysis, MC, HLT = 75 
  for (int i=0; i<16; i++){ 
    sprintf(name,"%s%s",mcnames[i].c_str()," 2012");
    if(int_exp_2012_75>0) {
      cout << "running over " << ((TTree*)mc_2012[i]->Get("AnaTree"))->GetEntries("") << " " << name << " events for HLT 75" <<  endl;   
      sprintf(name,"%s%s%s","results_gammaJ/events_",mcnames[i].c_str(),"_2012_HLT75.root");
      mc_2012_fill_75[i]->WriteRoot(name);             
      var_mc_2012_75[i]->Add( mc_2012_fill_75[i]->Plot(variableMC, name, nbin, min, max, i) );  
      std::cout << "Selected events on mc2012 " << name << " for HLT=75 " << var_mc_2012_75[i]->GetEntries() << std::endl;
    }
  }
  cout << endl;

  // 1) HLT = 90
  cout << endl;
  cout << "------------------- HLT = 90 -------------------" << endl; 

  // creating the fillers and setting cuts: data
  fillPlot2012_gammaJets data_fill_90((TTree*)data->Get("AnaTree"));
  data_fill_90.Setcuts(pt1min_90,pt1max_90,eb,r9,90);  

  // analysis, data, HLT = 90 
  cout << "running over " << ((TTree*)data->Get("AnaTree"))->GetEntries("") << " data events for HLT 90" <<  endl;
  sprintf(name,"results_gammaJ/events_HLT90.root");
  data_fill_90.WriteRoot(name);
  vardata_90->Add(data_fill_90.Plot(variableData,"data", nbin, min, max, 100)); 
  std::cout << "Selected events on data " << vardata_90->GetEntries() << " with HLT = 90" << std::endl;

  // creating the fillers and setting cuts: MC, HLT = 90
  fillPlot2012_gammaJets* mc_2012_fill_90[16];
  for (int i=0; i<16; i++){
    if(int_exp_2012_90>0) mc_2012_fill_90[i] = new fillPlot2012_gammaJets((TTree*)mc_2012[i]->Get("AnaTree"));   
    if(int_exp_2012_90>0) mc_2012_fill_90[i]->Setcuts(pt1min_90,pt1max_90,eb,r9,90); 
    mc_2012_fill_90[i]->DoPuReweight();
  }

  // analysis, MC, HLT = 90 
  for (int i=0; i<16; i++){ 
    sprintf(name,"%s%s",mcnames[i].c_str()," 2012");
    if(int_exp_2012_90>0) {
      cout << "running over " << ((TTree*)mc_2012[i]->Get("AnaTree"))->GetEntries("") << " " << name << " events for HLT 90" <<  endl;   
      sprintf(name,"%s%s%s","results_gammaJ/events_",mcnames[i].c_str(),"_2012_HLT90.root");
      mc_2012_fill_90[i]->WriteRoot(name);             
      var_mc_2012_90[i]->Add( mc_2012_fill_90[i]->Plot(variableMC, name, nbin, min, max, i) );  
      std::cout << "Selected events on mc2012 " << name << " for HLT=90 " << var_mc_2012_90[i]->GetEntries() << std::endl;
    }
  }
  cout << endl;


  // scale mc to equivalent lumi for each HLT path
  for (int i=0; i<16; i++){
    if(int_exp_2012_30>0) var_mc_2012_30[i]->Scale(scale_mc_2012_30[i]);  
    if(int_exp_2012_50>0) var_mc_2012_50[i]->Scale(scale_mc_2012_50[i]);  
    if(int_exp_2012_75>0) var_mc_2012_75[i]->Scale(scale_mc_2012_75[i]);  
    if(int_exp_2012_90>0) var_mc_2012_90[i]->Scale(scale_mc_2012_90[i]);  
  }

  // counting number of events passing selection (scaled)   
  double num_mc_2012_30[16], num_uns_mc_2012_30[16]; 
  double num_mc_2012_50[16], num_uns_mc_2012_50[16]; 
  double num_mc_2012_75[16], num_uns_mc_2012_75[16]; 
  double num_mc_2012_90[16], num_uns_mc_2012_90[16]; 

  for (int i=0; i<16; i++){ 
    num_mc_2012_30[i] = 0;
    if(int_exp_2012_30>0) num_mc_2012_30[i] = var_mc_2012_30[i]->Integral();        
    num_mc_2012_50[i] = 0;
    if(int_exp_2012_50>0) num_mc_2012_50[i] = var_mc_2012_50[i]->Integral();        
    num_mc_2012_75[i] = 0;
    if(int_exp_2012_75>0) num_mc_2012_75[i] = var_mc_2012_75[i]->Integral();        
    num_mc_2012_90[i] = 0;
    if(int_exp_2012_90>0) num_mc_2012_90[i] = var_mc_2012_90[i]->Integral();        
    // 
    num_uns_mc_2012_30[i] = 0;
    if(int_exp_2012_30>0) num_uns_mc_2012_30[i] = var_mc_2012_30[i]->Integral();        
    num_uns_mc_2012_50[i] = 0;
    if(int_exp_2012_50>0) num_uns_mc_2012_50[i] = var_mc_2012_50[i]->Integral();        
    num_uns_mc_2012_75[i] = 0;
    if(int_exp_2012_75>0) num_uns_mc_2012_75[i] = var_mc_2012_75[i]->Integral();        
    num_uns_mc_2012_90[i] = 0;
    if(int_exp_2012_90>0) num_uns_mc_2012_90[i] = var_mc_2012_90[i]->Integral();        
  }

  // scale control sample
  double num_data_30 = vardata_30->Integral();
  double num_data_50 = vardata_50->Integral();
  double num_data_75 = vardata_75->Integral();
  double num_data_90 = vardata_90->Integral();

  for (int j=0; j<2; j++){   
    int offset(0);
    if(j>0) offset = 9;    // to add gamma+jets contributions up 
    for (int k=0 ; k<16-j-offset; k++){   
      if(int_exp_2012_30>0) var_30[j]->Add(var_mc_2012_30[k]);
      if(int_exp_2012_50>0) var_50[j]->Add(var_mc_2012_50[k]);
      if(int_exp_2012_75>0) var_75[j]->Add(var_mc_2012_75[k]);
      if(int_exp_2012_90>0) var_90[j]->Add(var_mc_2012_90[k]);
    }	
  }

  // final plots
  char ytitle_30[100], ytitle_50[100], ytitle_75[100], ytitle_90[100];
  sprintf(ytitle_30,"%s%d%s","N_{ev}/",int(int_exp_2012_30),"pb^{-1}");
  sprintf(ytitle_50,"%s%d%s","N_{ev}/",int(int_exp_2012_50),"pb^{-1}");
  sprintf(ytitle_75,"%s%d%s","N_{ev}/",int(int_exp_2012_75),"pb^{-1}");
  sprintf(ytitle_90,"%s%d%s","N_{ev}/",int(int_exp_2012_90),"pb^{-1}");
  for(int i=0; i<2; i++){
    var_30[i]->SetTitle("");
    var_30[i]->SetStats(0);
    var_30[i]->SetTitleOffset(1.25,"Y");
    var_30[i]->SetYTitle(ytitle_30);
    var_30[i]->SetXTitle(axis.c_str());
    var_30[i]->SetLineColor(kBlack);
    var_30[i]->SetLineWidth(2);
    //
    var_50[i]->SetTitle("");
    var_50[i]->SetStats(0);
    var_50[i]->SetTitleOffset(1.25,"Y");
    var_50[i]->SetYTitle(ytitle_50);
    var_50[i]->SetXTitle(axis.c_str());
    var_50[i]->SetLineColor(kBlack);
    var_50[i]->SetLineWidth(2);
    //
    var_75[i]->SetTitle("");
    var_75[i]->SetStats(0);
    var_75[i]->SetTitleOffset(1.25,"Y");
    var_75[i]->SetYTitle(ytitle_75);
    var_75[i]->SetXTitle(axis.c_str());
    var_75[i]->SetLineColor(kBlack);
    var_75[i]->SetLineWidth(2);
    //
    var_90[i]->SetTitle("");
    var_90[i]->SetStats(0);
    var_90[i]->SetTitleOffset(1.25,"Y");
    var_90[i]->SetYTitle(ytitle_90);
    var_90[i]->SetXTitle(axis.c_str());
    var_90[i]->SetLineColor(kBlack);
    var_90[i]->SetLineWidth(2);
  }


  // ----------------------------------------
  TLegendEntry *legge;
  TLegend *leg;
  leg = new TLegend(0.6,0.6,0.85,0.85);
  leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextSize(0.05);
  leg->SetFillColor(0);
  legge = leg->AddEntry(var_30[0], "gamma+jets", "f");
  legge = leg->AddEntry(var_30[1], "QCD", "f");

  // mc only plot: data vs background, HLT=30
  var_30[0]->SetFillColor(kBlue-9);
  var_30[0]->Draw("hist");
  var_30[1]->SetFillColor(kMagenta-9);
  var_30[1]->Draw("samehist");
  leg->Draw();
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_HLT-30.png");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_HLT-30.root");
  c0->SaveAs(name);

  // mc only plot: data vs background, HLT=50
  var_50[0]->SetFillColor(kBlue-9);
  var_50[0]->Draw("hist");
  var_50[1]->SetFillColor(kMagenta-9);
  var_50[1]->Draw("samehist");
  leg->Draw();
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_HLT-50.png");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_HLT-50.root");
  c0->SaveAs(name);

  // mc only plot: data vs background, HLT=75
  var_75[0]->SetFillColor(kBlue-9);
  var_75[0]->Draw("hist");
  var_75[1]->SetFillColor(kMagenta-9);
  var_75[1]->Draw("samehist");
  leg->Draw();
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_HLT-75.png");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_HLT-75.root");
  c0->SaveAs(name);

  // mc only plot: data vs background, HLT=90
  var_90[0]->SetFillColor(kBlue-9);
  var_90[0]->Draw("hist");
  var_90[1]->SetFillColor(kMagenta-9);
  var_90[1]->Draw("samehist");
  leg->Draw();
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_HLT-90.png");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_HLT-90.root");
  c0->SaveAs(name);

  // all together, mc only
  TH1D* var_all_0 = (TH1D*) var_30[0]->Clone("var_all_0");
  TH1D* var_all_1 = (TH1D*) var_30[1]->Clone("var_all_1");
  var_all_0->Add(var_50[0]);
  var_all_0->Add(var_75[0]);
  var_all_0->Add(var_90[0]);
  var_all_1->Add(var_50[1]);
  var_all_1->Add(var_75[1]);
  var_all_1->Add(var_90[1]);
  var_all_0->SetFillColor(kBlue-9);
  var_all_0->Draw("hist");
  var_all_1->SetFillColor(kMagenta-9);
  var_all_1->Draw("samehist");
  leg->Draw();
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_all.png");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/mc_",variableData.c_str(),"_all.root");
  c0->SaveAs(name);  

  // ------------------------------------
  // data only plot, HLT = 30
  vardata_30->SetXTitle(axis.c_str());
  vardata_30->SetTitle("");
  vardata_30->SetStats(0);
  vardata_30->SetMarkerStyle(8);
  vardata_30->SetMarkerSize(.9);
  vardata_30->SetTitleOffset(1.25,"Y");
  vardata_30->Draw("pe");
  sprintf(name,"%s%s%s","results_gammaJ/data_",variableData.c_str(),"_HLT-30.png");
  c0->SaveAs(name);

  // data only plot, HLT = 50
  vardata_50->SetXTitle(axis.c_str());
  vardata_50->SetTitle("");
  vardata_50->SetStats(0);
  vardata_50->SetMarkerStyle(8);
  vardata_50->SetMarkerSize(.9);
  vardata_50->SetTitleOffset(1.25,"Y");
  vardata_50->Draw("pe");
  sprintf(name,"%s%s%s","results_gammaJ/data_",variableData.c_str(),"_HLT-50.png");
  c0->SaveAs(name);

  // data only plot, HLT = 75
  vardata_75->SetXTitle(axis.c_str());
  vardata_75->SetTitle("");
  vardata_75->SetStats(0);
  vardata_75->SetMarkerStyle(8);
  vardata_75->SetMarkerSize(.9);
  vardata_75->SetTitleOffset(1.25,"Y");
  vardata_75->Draw("pe");
  sprintf(name,"%s%s%s","results_gammaJ/data_",variableData.c_str(),"_HLT-75.png");
  c0->SaveAs(name);

  // data only plot, HLT = 90
  vardata_90->SetXTitle(axis.c_str());
  vardata_90->SetTitle("");
  vardata_90->SetStats(0);
  vardata_90->SetMarkerStyle(8);
  vardata_90->SetMarkerSize(.9);
  vardata_90->SetTitleOffset(1.25,"Y");
  vardata_90->Draw("pe");
  sprintf(name,"%s%s%s","results_gammaJ/data_",variableData.c_str(),"_HLT-90.png");
  c0->SaveAs(name);

  // all together
  TH1D* vardata_all = (TH1D*) vardata_30->Clone("vardata_all");
  vardata_all->Add(vardata_50);
  vardata_all->Add(vardata_75);
  vardata_all->Add(vardata_90);
  vardata_all->SetXTitle(axis.c_str());
  vardata_all->SetTitle("");
  vardata_all->SetStats(0);
  vardata_all->SetMarkerStyle(8);
  vardata_all->SetMarkerSize(.9);
  vardata_all->SetTitleOffset(1.25,"Y");
  vardata_all->Draw("pe");
  sprintf(name,"%s%s%s","results_gammaJ/data_",variableData.c_str(),"_all.png");
  c0->SaveAs(name);

  // -----------------------------------------------
  // data overlaid to mc
  legge = leg->AddEntry(vardata_30, "data", "p");

  double themax_30 = vardata_30->GetMaximum();
  if(var_30[0]->GetMaximum()>themax_30) themax_30 = var_30[0]->GetMaximum();
  if (themax_30>0) {  
    if ( variableData == "etaphot1" || variableData == "phiphot1" ) 
      vardata_30->SetMaximum(themax_30*2.0);
    else
      vardata_30->SetMaximum(themax_30*1.1);
    vardata_30->SetMinimum(0.000001);
  } else {
    vardata_30->SetMaximum(0.00001);
  }

  double themax_50 = vardata_50->GetMaximum();
  if(var_50[0]->GetMaximum()>themax_50) themax_50 = var_50[0]->GetMaximum();
  if (themax_50>0) {  
    if ( variableData == "etaphot1" || variableData == "phiphot1" ) 
      vardata_50->SetMaximum(themax_50*2.0);
    else
      vardata_50->SetMaximum(themax_50*1.1);
    vardata_50->SetMinimum(0.000001);
  } else {
    vardata_50->SetMaximum(0.00001);
  }

  double themax_75 = vardata_75->GetMaximum();
  if(var_75[0]->GetMaximum()>themax_75) themax_75 = var_75[0]->GetMaximum();
  if (themax_75>0) {  
    if ( variableData == "etaphot1" || variableData == "phiphot1" ) 
      vardata_75->SetMaximum(themax_75*2.0);
    else
      vardata_75->SetMaximum(themax_75*1.1);
    vardata_75->SetMinimum(0.000001);
  } else {
    vardata_75->SetMaximum(0.00001);
  }

  double themax_90 = vardata_90->GetMaximum();
  if(var_90[0]->GetMaximum()>themax_90) themax_90 = var_90[0]->GetMaximum();
  if (themax_90>0) {
    if ( variableData == "etaphot1" || variableData == "phiphot1" ) 
      vardata_90->SetMaximum(themax_90*2.0);
    else
      vardata_90->SetMaximum(themax_90*1.1);
    vardata_90->SetMinimum(0.000001);
  } else {
    vardata_90->SetMaximum(0.00001);
  }

  double themax_all = vardata_all->GetMaximum();
  if(var_all_0->GetMaximum()>themax_all) themax_all = var_all_0->GetMaximum();
  if (themax_all>0) {
    if ( variableData == "etaphot1" || variableData == "phiphot1" ) 
      vardata_all->SetMaximum(themax_all*2.0);
    else
      vardata_all->SetMaximum(themax_all*1.1);
    vardata_all->SetMinimum(0.000001);
  } else {
    vardata_all->SetMaximum(0.00001);
  }

  for(int ii=0; ii<2; ii++) var_30[ii]->SetMinimum(0.000001);
  for(int ii=0; ii<2; ii++) var_50[ii]->SetMinimum(0.000001);
  for(int ii=0; ii<2; ii++) var_75[ii]->SetMinimum(0.000001);
  for(int ii=0; ii<2; ii++) var_90[ii]->SetMinimum(0.000001);
  for(int ii=0; ii<2; ii++) var_all_0->SetMinimum(0.000001);
  for(int ii=0; ii<2; ii++) var_all_1->SetMinimum(0.000001);

  //
  vardata_30->Draw("pe");
  var_30[0]->Draw("samehist");
  var_30[1]->Draw("samehist");
  leg->Draw();
  vardata_30->Draw("pesame");
  gPad->RedrawAxis();
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_30.root");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_30.png");
  c0->SaveAs(name);
  //
  vardata_50->Draw("pe");
  var_50[0]->Draw("samehist");
  var_50[1]->Draw("samehist");
  leg->Draw();
  vardata_50->Draw("pesame");
  gPad->RedrawAxis();
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_50.root");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_50.png");
  c0->SaveAs(name);
  //
  vardata_75->Draw("pe");
  var_75[0]->Draw("samehist");
  var_75[1]->Draw("samehist");
  leg->Draw();
  vardata_75->Draw("pesame");
  gPad->RedrawAxis();
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_75.root");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_75.png");
  c0->SaveAs(name);
  //
  vardata_90->Draw("pe");
  var_90[0]->Draw("samehist");
  var_90[1]->Draw("samehist");
  leg->Draw();
  vardata_90->Draw("pesame");
  gPad->RedrawAxis();
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_90.root");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_90.png");
  c0->SaveAs(name);
  //
  vardata_all->Draw("pe");
  var_all_0->Draw("samehist");
  var_all_1->Draw("samehist");
  leg->Draw();
  vardata_all->Draw("pesame");
  gPad->RedrawAxis();
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_all.root");
  c0->SaveAs(name);
  sprintf(name,"%s%s%s","results_gammaJ/data-mc_",variableData.c_str(),"_all.png");
  c0->SaveAs(name);

  // -------------------------------------------------------------------------
  sprintf(name,"results_gammaJ/yields.txt");
  ofstream outfile(name);  
  outfile << "####################################" << endl;
  outfile << "CUTS " << endl;
  outfile << "####################################" << endl;
  outfile << "ptphot1, HLT = 30 : " << pt1min_30 << " - " << pt1max_30 << endl;
  outfile << "ptphot1, HLT = 50 : " << pt1min_50 << " - " << pt1max_50 << endl; 
  outfile << "ptphot1, HLT = 75 : " << pt1min_75 << " - " << pt1max_75 << endl; 
  outfile << "ptphot1, HLT = 90 : " << pt1min_90 << " - " << pt1max_90 << endl; 
  outfile << "ebcat : " << eb << endl;
  outfile << "r9cat : " << r9 << endl;
  outfile << endl;
  outfile << "####################################" << endl;
  outfile << "N of generated events" << endl;
  outfile << "####################################" << endl;
  outfile << "# events QCD, 20-30 = "       << n_mc_2012[0]  << endl;
  outfile << "# events QCD, 30-80 = "       << n_mc_2012[1]  << endl;
  outfile << "# events QCD, 80-170 = "      << n_mc_2012[2]  << endl;
  outfile << "# events QCD, 170-250 = "     << n_mc_2012[3]  << endl;
  outfile << "# events QCD, 250-350 = "     << n_mc_2012[4]  << endl;
  outfile << "# events QCD, >350 = "        << n_mc_2012[5]  << endl;
  outfile << "# events g+jet, 0-15 = "      << n_mc_2012[6]  << endl;
  outfile << "# events g+jet, 15-30 = "     << n_mc_2012[7]  << endl;
  outfile << "# events g+jet, 30-50 = "     << n_mc_2012[8]  << endl;
  outfile << "# events g+jet, 50-80 = "     << n_mc_2012[9]  << endl;
  outfile << "# events g+jet, 80-120 = "    << n_mc_2012[10] << endl;
  outfile << "# events g+jet, 120-170 = "   << n_mc_2012[11] << endl;
  outfile << "# events g+jet, 170-300 = "   << n_mc_2012[12] << endl;
  outfile << "# events g+jet, 470-800 = "   << n_mc_2012[13] << endl;
  outfile << "# events g+jet, 800-1400 = "  << n_mc_2012[14] << endl;
  outfile << "# events g+jet, 1400-1800 = " << n_mc_2012[15] << endl;
  outfile << endl;
  outfile << "N of selected events, HLT = 30 (not scaled for lumi)"     << endl;  
  outfile << "########################################################" << endl;
  outfile << "# events QCD, 20-30 = "       << num_uns_mc_2012_30[0]  << endl;
  outfile << "# events QCD, 30-80 = "       << num_uns_mc_2012_30[1]  << endl;
  outfile << "# events QCD, 80-170 = "      << num_uns_mc_2012_30[2]  << endl;
  outfile << "# events QCD, 170-250 = "     << num_uns_mc_2012_30[3]  << endl;
  outfile << "# events QCD, 250-350 = "     << num_uns_mc_2012_30[4]  << endl;
  outfile << "# events QCD, >350 = "        << num_uns_mc_2012_30[5]  << endl;
  outfile << "# events g+jet, 0-15 = "      << num_uns_mc_2012_30[6]  << endl;
  outfile << "# events g+jet, 15-30 = "     << num_uns_mc_2012_30[7]  << endl;
  outfile << "# events g+jet, 30-50 = "     << num_uns_mc_2012_30[8]  << endl;
  outfile << "# events g+jet, 50-80 = "     << num_uns_mc_2012_30[9]  << endl;
  outfile << "# events g+jet, 80-120 = "    << num_uns_mc_2012_30[10] << endl;
  outfile << "# events g+jet, 120-170 = "   << num_uns_mc_2012_30[11] << endl;
  outfile << "# events g+jet, 170-300 = "   << num_uns_mc_2012_30[12] << endl;
  outfile << "# events g+jet, 470-800 = "   << num_uns_mc_2012_30[13] << endl;
  outfile << "# events g+jet, 800-1400 = "  << num_uns_mc_2012_30[14] << endl;
  outfile << "# events g+jet, 1400-1800 = " << num_uns_mc_2012_30[15] << endl;
  outfile << "ndata = " << num_data_30 << endl;
  outfile << endl;
  outfile << "N of selected events, HLT = 50 (not scaled for lumi)"     << endl;  
  outfile << "########################################################" << endl;
  outfile << "# events QCD, 20-30 = "       << num_uns_mc_2012_50[0]  << endl;
  outfile << "# events QCD, 30-80 = "       << num_uns_mc_2012_50[1]  << endl;
  outfile << "# events QCD, 80-170 = "      << num_uns_mc_2012_50[2]  << endl;
  outfile << "# events QCD, 170-250 = "     << num_uns_mc_2012_50[3]  << endl;
  outfile << "# events QCD, 250-350 = "     << num_uns_mc_2012_50[4]  << endl;
  outfile << "# events QCD, >350 = "        << num_uns_mc_2012_50[5]  << endl;
  outfile << "# events g+jet, 0-15 = "      << num_uns_mc_2012_50[6]  << endl;
  outfile << "# events g+jet, 15-30 = "     << num_uns_mc_2012_50[7]  << endl;
  outfile << "# events g+jet, 30-50 = "     << num_uns_mc_2012_50[8]  << endl;
  outfile << "# events g+jet, 50-80 = "     << num_uns_mc_2012_50[9]  << endl;
  outfile << "# events g+jet, 80-120 = "    << num_uns_mc_2012_50[10] << endl;
  outfile << "# events g+jet, 120-170 = "   << num_uns_mc_2012_50[11] << endl;
  outfile << "# events g+jet, 170-300 = "   << num_uns_mc_2012_50[12] << endl;
  outfile << "# events g+jet, 470-800 = "   << num_uns_mc_2012_50[13] << endl;
  outfile << "# events g+jet, 800-1400 = "  << num_uns_mc_2012_50[14] << endl;
  outfile << "# events g+jet, 1400-1800 = " << num_uns_mc_2012_50[15] << endl;
  outfile << "ndata = " << num_data_50 << endl;
  outfile << endl;
  outfile << "N of selected events, HLT = 75 (not scaled for lumi)"     << endl;  
  outfile << "########################################################" << endl;
  outfile << "# events QCD, 20-30 = "       << num_uns_mc_2012_75[0]  << endl;
  outfile << "# events QCD, 30-80 = "       << num_uns_mc_2012_75[1]  << endl;
  outfile << "# events QCD, 80-170 = "      << num_uns_mc_2012_75[2]  << endl;
  outfile << "# events QCD, 170-250 = "     << num_uns_mc_2012_75[3]  << endl;
  outfile << "# events QCD, 250-350 = "     << num_uns_mc_2012_75[4]  << endl;
  outfile << "# events QCD, >350 = "        << num_uns_mc_2012_75[5]  << endl;
  outfile << "# events g+jet, 0-15 = "      << num_uns_mc_2012_75[6]  << endl;
  outfile << "# events g+jet, 15-30 = "     << num_uns_mc_2012_75[7]  << endl;
  outfile << "# events g+jet, 30-50 = "     << num_uns_mc_2012_75[8]  << endl;
  outfile << "# events g+jet, 50-80 = "     << num_uns_mc_2012_75[9]  << endl;
  outfile << "# events g+jet, 80-120 = "    << num_uns_mc_2012_75[10] << endl;
  outfile << "# events g+jet, 120-170 = "   << num_uns_mc_2012_75[11] << endl;
  outfile << "# events g+jet, 170-300 = "   << num_uns_mc_2012_75[12] << endl;
  outfile << "# events g+jet, 470-800 = "   << num_uns_mc_2012_75[13] << endl;
  outfile << "# events g+jet, 800-1400 = "  << num_uns_mc_2012_75[14] << endl;
  outfile << "# events g+jet, 1400-1800 = " << num_uns_mc_2012_75[15] << endl;
  outfile << "ndata = " << num_data_75 << endl;
  outfile << endl;
  outfile << "N of selected events, HLT = 90 (not scaled for lumi)"     << endl;  
  outfile << "########################################################" << endl;
  outfile << "# events QCD, 20-30 = "       << num_uns_mc_2012_90[0]  << endl;
  outfile << "# events QCD, 30-80 = "       << num_uns_mc_2012_90[1]  << endl;
  outfile << "# events QCD, 80-170 = "      << num_uns_mc_2012_90[2]  << endl;
  outfile << "# events QCD, 170-250 = "     << num_uns_mc_2012_90[3]  << endl;
  outfile << "# events QCD, 250-350 = "     << num_uns_mc_2012_90[4]  << endl;
  outfile << "# events QCD, >350 = "        << num_uns_mc_2012_90[5]  << endl;
  outfile << "# events g+jet, 0-15 = "      << num_uns_mc_2012_90[6]  << endl;
  outfile << "# events g+jet, 15-30 = "     << num_uns_mc_2012_90[7]  << endl;
  outfile << "# events g+jet, 30-50 = "     << num_uns_mc_2012_90[8]  << endl;
  outfile << "# events g+jet, 50-80 = "     << num_uns_mc_2012_90[9]  << endl;
  outfile << "# events g+jet, 80-120 = "    << num_uns_mc_2012_90[10] << endl;
  outfile << "# events g+jet, 120-170 = "   << num_uns_mc_2012_90[11] << endl;
  outfile << "# events g+jet, 170-300 = "   << num_uns_mc_2012_90[12] << endl;
  outfile << "# events g+jet, 470-800 = "   << num_uns_mc_2012_90[13] << endl;
  outfile << "# events g+jet, 800-1400 = "  << num_uns_mc_2012_90[14] << endl;
  outfile << "# events g+jet, 1400-1800 = " << num_uns_mc_2012_90[15] << endl;
  outfile << "ndata = " << num_data_90 << endl;
  outfile << endl;

  double num_bkg_30(0), err_num_bkg_30(0);
  double num_bkg_50(0), err_num_bkg_50(0);
  double num_bkg_75(0), err_num_bkg_75(0);
  double num_bkg_90(0), err_num_bkg_90(0);
  double num_mc_total_30[16],num_uns_mc_total_30[16], n_mc_total_30[16], err_num_mc_total_30[16], err_num_uns_mc_total_30[16];
  double num_mc_total_50[16],num_uns_mc_total_50[16], n_mc_total_50[16], err_num_mc_total_50[16], err_num_uns_mc_total_50[16];
  double num_mc_total_75[16],num_uns_mc_total_75[16], n_mc_total_75[16], err_num_mc_total_75[16], err_num_uns_mc_total_75[16];
  double num_mc_total_90[16],num_uns_mc_total_90[16], n_mc_total_90[16], err_num_mc_total_90[16], err_num_uns_mc_total_90[16];
  for (int i=0; i<16; i++){
    if(i<6) num_bkg_30 += num_mc_2012_30[i];
    if(i<6) num_bkg_50 += num_mc_2012_50[i];
    if(i<6) num_bkg_75 += num_mc_2012_75[i];
    if(i<6) num_bkg_90 += num_mc_2012_90[i];
    num_mc_total_30[i] = num_mc_2012_30[i];
    num_mc_total_50[i] = num_mc_2012_50[i];
    num_mc_total_75[i] = num_mc_2012_75[i];
    num_mc_total_90[i] = num_mc_2012_90[i];
    num_uns_mc_total_30[i] = num_uns_mc_2012_30[i];
    num_uns_mc_total_50[i] = num_uns_mc_2012_50[i];
    num_uns_mc_total_75[i] = num_uns_mc_2012_75[i];
    num_uns_mc_total_90[i] = num_uns_mc_2012_90[i];

    err_num_uns_mc_total_30[i] = sqrt(num_uns_mc_total_30[i]);
    err_num_uns_mc_total_50[i] = sqrt(num_uns_mc_total_50[i]);
    err_num_uns_mc_total_75[i] = sqrt(num_uns_mc_total_75[i]);
    err_num_uns_mc_total_90[i] = sqrt(num_uns_mc_total_90[i]);
    if(num_uns_mc_total_30[i]) err_num_mc_total_30[i] = err_num_uns_mc_total_30[i] * num_mc_total_30[i]/num_uns_mc_total_30[i];
    else err_num_mc_total_30[i] = 0;

    if(num_uns_mc_total_50[i]) err_num_mc_total_50[i] = err_num_uns_mc_total_50[i] * num_mc_total_50[i]/num_uns_mc_total_50[i];
    else err_num_mc_total_50[i] = 0;

    if(num_uns_mc_total_75[i]) err_num_mc_total_75[i] = err_num_uns_mc_total_75[i] * num_mc_total_75[i]/num_uns_mc_total_75[i];
    else err_num_mc_total_75[i] = 0;

    if(num_uns_mc_total_90[i]) err_num_mc_total_90[i] = err_num_uns_mc_total_90[i] * num_mc_total_90[i]/num_uns_mc_total_90[i];
    else err_num_mc_total_90[i] = 0;

    n_mc_total_30[i] = n_mc_2012[i] * scale_mc_2012_30[i];
    n_mc_total_50[i] = n_mc_2012[i] * scale_mc_2012_50[i];
    n_mc_total_75[i] = n_mc_2012[i] * scale_mc_2012_75[i];
    n_mc_total_90[i] = n_mc_2012[i] * scale_mc_2012_90[i];
  }

  for (int i=0; i<6; i++){ 
    err_num_bkg_30 = sqrt(err_num_bkg_30*err_num_bkg_30 + err_num_mc_total_30[i]*err_num_mc_total_30[i]);
    err_num_bkg_50 = sqrt(err_num_bkg_50*err_num_bkg_50 + err_num_mc_total_50[i]*err_num_mc_total_50[i]);
    err_num_bkg_75= sqrt(err_num_bkg_75*err_num_bkg_75 + err_num_mc_total_75[i]*err_num_mc_total_75[i]);
    err_num_bkg_90 = sqrt(err_num_bkg_90*err_num_bkg_90 + err_num_mc_total_90[i]*err_num_mc_total_90[i]);
  }
  
  outfile << endl;
  outfile << "final numbers, HLT = 30" << endl;
  outfile << "nallbkg        = " << num_bkg_30 << " +/- " << err_num_bkg_30 << endl;
  outfile << "QCD, 20-30     = " << num_mc_total_30[0]  << " +/- " << err_num_mc_total_30[0]  << endl;
  outfile << "QCD, 30-80     = " << num_mc_total_30[1]  << " +/- " << err_num_mc_total_30[1]  << endl;
  outfile << "QCD, 80-170    = " << num_mc_total_30[2]  << " +/- " << err_num_mc_total_30[2]  << endl;
  outfile << "QCD, 170-250   = " << num_mc_total_30[3]  << " +/- " << err_num_mc_total_30[3]  << endl;
  outfile << "QCD, 250-350   = " << num_mc_total_30[4]  << " +/- " << err_num_mc_total_30[4]  << endl;
  outfile << "QCD, >350      = " << num_mc_total_30[5]  << " +/- " << err_num_mc_total_30[5]  << endl;
  outfile << "G+j, 0-15      = " << num_mc_total_30[6]  << " +/- " << err_num_mc_total_30[6]  << endl;
  outfile << "G+j, 15-30     = " << num_mc_total_30[7]  << " +/- " << err_num_mc_total_30[7]  << endl;
  outfile << "G+j, 30-50     = " << num_mc_total_30[8]  << " +/- " << err_num_mc_total_30[8]  << endl;
  outfile << "G+j, 50-80     = " << num_mc_total_30[9]  << " +/- " << err_num_mc_total_30[9]  << endl;
  outfile << "G+j, 80-120    = " << num_mc_total_30[10] << " +/- " << err_num_mc_total_30[10]  << endl;
  outfile << "G+j, 120-170   = " << num_mc_total_30[11] << " +/- " << err_num_mc_total_30[11]  << endl;
  outfile << "G+j, 170-300   = " << num_mc_total_30[12] << " +/- " << err_num_mc_total_30[12]  << endl;
  outfile << "G+j, 470-800   = " << num_mc_total_30[13] << " +/- " << err_num_mc_total_30[13]  << endl;
  outfile << "G+j, 800-1400  = " << num_mc_total_30[14] << " +/- " << err_num_mc_total_30[14]  << endl;
  outfile << "G+j, 1400-1800 = " << num_mc_total_30[15] << " +/- " << err_num_mc_total_30[15]  << endl;
  outfile << endl;          
  outfile << endl;
  outfile << "eff gamma+jets = "  << (num_mc_total_30[6] + num_mc_total_30[7] + num_mc_total_30[8] + num_mc_total_30[9] + num_mc_total_30[10] + num_mc_total_30[11] + num_mc_total_30[12] + num_mc_total_30[13] + num_mc_total_30[14] + num_mc_total_30[15])/(n_mc_total_30[6] + n_mc_total_30[7] + n_mc_total_30[8] + n_mc_total_30[9] + n_mc_total_30[10] + n_mc_total_30[11] + n_mc_total_30[12] + n_mc_total_30[13] + n_mc_total_30[14] + n_mc_total_30[15]) << endl;  
  
  outfile << endl;
  outfile << "final numbers, HLT = 50" << endl;
  outfile << "nallbkg        = " << num_bkg_50 << " +/- " << err_num_bkg_50 << endl;
  outfile << "QCD, 20-30     = " << num_mc_total_50[0]  << " +/- " << err_num_mc_total_50[0]  << endl;
  outfile << "QCD, 30-80     = " << num_mc_total_50[1]  << " +/- " << err_num_mc_total_50[1]  << endl;
  outfile << "QCD, 80-170    = " << num_mc_total_50[2]  << " +/- " << err_num_mc_total_50[2]  << endl;
  outfile << "QCD, 170-250   = " << num_mc_total_50[3]  << " +/- " << err_num_mc_total_50[3]  << endl;
  outfile << "QCD, 250-350   = " << num_mc_total_50[4]  << " +/- " << err_num_mc_total_50[4]  << endl;
  outfile << "QCD, >350      = " << num_mc_total_50[5]  << " +/- " << err_num_mc_total_50[5]  << endl;
  outfile << "G+j, 0-15      = " << num_mc_total_50[6]  << " +/- " << err_num_mc_total_50[6]  << endl;
  outfile << "G+j, 15-30     = " << num_mc_total_50[7]  << " +/- " << err_num_mc_total_50[7]  << endl;
  outfile << "G+j, 30-50     = " << num_mc_total_50[8]  << " +/- " << err_num_mc_total_50[8]  << endl;
  outfile << "G+j, 50-80     = " << num_mc_total_50[9]  << " +/- " << err_num_mc_total_50[9]  << endl;
  outfile << "G+j, 80-120    = " << num_mc_total_50[10] << " +/- " << err_num_mc_total_50[10]  << endl;
  outfile << "G+j, 120-170   = " << num_mc_total_50[11] << " +/- " << err_num_mc_total_50[11]  << endl;
  outfile << "G+j, 170-300   = " << num_mc_total_50[12] << " +/- " << err_num_mc_total_50[12]  << endl;
  outfile << "G+j, 470-800   = " << num_mc_total_50[13] << " +/- " << err_num_mc_total_50[13]  << endl;
  outfile << "G+j, 800-1400  = " << num_mc_total_50[14] << " +/- " << err_num_mc_total_50[14]  << endl;
  outfile << "G+j, 1400-1800 = " << num_mc_total_50[15] << " +/- " << err_num_mc_total_50[15]  << endl;
  outfile << endl;          
  outfile << endl;
  outfile << "eff gamma+jets = "  << (num_mc_total_50[6] + num_mc_total_50[7] + num_mc_total_50[8] + num_mc_total_50[9] + num_mc_total_50[10] + num_mc_total_50[11] + num_mc_total_50[12] + num_mc_total_50[13] + num_mc_total_50[14] + num_mc_total_50[15])/(n_mc_total_50[6] + n_mc_total_50[7] + n_mc_total_50[8] + n_mc_total_50[9] + n_mc_total_50[10] + n_mc_total_50[11] + n_mc_total_50[12] + n_mc_total_50[13] + n_mc_total_50[14] + n_mc_total_50[15]) << endl;  
  
  outfile << endl;
  outfile << "final numbers, HLT = 75" << endl;
  outfile << "nallbkg        = " << num_bkg_75 << " +/- " << err_num_bkg_75 << endl;
  outfile << "QCD, 20-30     = " << num_mc_total_75[0]  << " +/- " << err_num_mc_total_75[0]  << endl;
  outfile << "QCD, 30-80     = " << num_mc_total_75[1]  << " +/- " << err_num_mc_total_75[1]  << endl;
  outfile << "QCD, 80-170    = " << num_mc_total_75[2]  << " +/- " << err_num_mc_total_75[2]  << endl;
  outfile << "QCD, 170-250   = " << num_mc_total_75[3]  << " +/- " << err_num_mc_total_75[3]  << endl;
  outfile << "QCD, 250-350   = " << num_mc_total_75[4]  << " +/- " << err_num_mc_total_75[4]  << endl;
  outfile << "QCD, >350      = " << num_mc_total_75[5]  << " +/- " << err_num_mc_total_75[5]  << endl;
  outfile << "G+j, 0-15      = " << num_mc_total_75[6]  << " +/- " << err_num_mc_total_75[6]  << endl;
  outfile << "G+j, 15-30     = " << num_mc_total_75[7]  << " +/- " << err_num_mc_total_75[7]  << endl;
  outfile << "G+j, 30-50     = " << num_mc_total_75[8]  << " +/- " << err_num_mc_total_75[8]  << endl;
  outfile << "G+j, 50-80     = " << num_mc_total_75[9]  << " +/- " << err_num_mc_total_75[9]  << endl;
  outfile << "G+j, 80-120    = " << num_mc_total_75[10] << " +/- " << err_num_mc_total_75[10]  << endl;
  outfile << "G+j, 120-170   = " << num_mc_total_75[11] << " +/- " << err_num_mc_total_75[11]  << endl;
  outfile << "G+j, 170-300   = " << num_mc_total_75[12] << " +/- " << err_num_mc_total_75[12]  << endl;
  outfile << "G+j, 470-800   = " << num_mc_total_75[13] << " +/- " << err_num_mc_total_75[13]  << endl;
  outfile << "G+j, 800-1400  = " << num_mc_total_75[14] << " +/- " << err_num_mc_total_75[14]  << endl;
  outfile << "G+j, 1400-1800 = " << num_mc_total_75[15] << " +/- " << err_num_mc_total_75[15]  << endl;
  outfile << endl;          
  outfile << endl;
  outfile << "eff gamma+jets = "  << (num_mc_total_75[6] + num_mc_total_75[7] + num_mc_total_75[8] + num_mc_total_75[9] + num_mc_total_75[10] + num_mc_total_75[11] + num_mc_total_75[12] + num_mc_total_75[13] + num_mc_total_75[14] + num_mc_total_75[15])/(n_mc_total_75[6] + n_mc_total_75[7] + n_mc_total_75[8] + n_mc_total_75[9] + n_mc_total_75[10] + n_mc_total_75[11] + n_mc_total_75[12] + n_mc_total_75[13] + n_mc_total_75[14] + n_mc_total_75[15]) << endl;  
  
  outfile << endl;
  outfile << "final numbers, HLT = 90" << endl;
  outfile << "nallbkg        = " << num_bkg_90 << " +/- " << err_num_bkg_90 << endl;
  outfile << "QCD, 20-30     = " << num_mc_total_90[0]  << " +/- " << err_num_mc_total_90[0]  << endl;
  outfile << "QCD, 30-80     = " << num_mc_total_90[1]  << " +/- " << err_num_mc_total_90[1]  << endl;
  outfile << "QCD, 80-170    = " << num_mc_total_90[2]  << " +/- " << err_num_mc_total_90[2]  << endl;
  outfile << "QCD, 170-250   = " << num_mc_total_90[3]  << " +/- " << err_num_mc_total_90[3]  << endl;
  outfile << "QCD, 250-350   = " << num_mc_total_90[4]  << " +/- " << err_num_mc_total_90[4]  << endl;
  outfile << "QCD, >350      = " << num_mc_total_90[5]  << " +/- " << err_num_mc_total_90[5]  << endl;
  outfile << "G+j, 0-15      = " << num_mc_total_90[6]  << " +/- " << err_num_mc_total_90[6]  << endl;
  outfile << "G+j, 15-30     = " << num_mc_total_90[7]  << " +/- " << err_num_mc_total_90[7]  << endl;
  outfile << "G+j, 30-50     = " << num_mc_total_90[8]  << " +/- " << err_num_mc_total_90[8]  << endl;
  outfile << "G+j, 50-80     = " << num_mc_total_90[9]  << " +/- " << err_num_mc_total_90[9]  << endl;
  outfile << "G+j, 80-120    = " << num_mc_total_90[10] << " +/- " << err_num_mc_total_90[10]  << endl;
  outfile << "G+j, 120-170   = " << num_mc_total_90[11] << " +/- " << err_num_mc_total_90[11]  << endl;
  outfile << "G+j, 170-300   = " << num_mc_total_90[12] << " +/- " << err_num_mc_total_90[12]  << endl;
  outfile << "G+j, 470-800   = " << num_mc_total_90[13] << " +/- " << err_num_mc_total_90[13]  << endl;
  outfile << "G+j, 800-1400  = " << num_mc_total_90[14] << " +/- " << err_num_mc_total_90[14]  << endl;
  outfile << "G+j, 1400-1800 = " << num_mc_total_90[15] << " +/- " << err_num_mc_total_90[15]  << endl;
  outfile << endl;          
  outfile << endl;
  outfile << "eff gamma+jets = "  << (num_mc_total_90[6] + num_mc_total_90[7] + num_mc_total_90[8] + num_mc_total_90[9] + num_mc_total_90[10] + num_mc_total_90[11] + num_mc_total_90[12] + num_mc_total_90[13] + num_mc_total_90[14] + num_mc_total_90[15])/(n_mc_total_90[6] + n_mc_total_90[7] + n_mc_total_90[8] + n_mc_total_90[9] + n_mc_total_90[10] + n_mc_total_90[11] + n_mc_total_90[12] + n_mc_total_90[13] + n_mc_total_90[14] + n_mc_total_90[15]) << endl;  
  cout << endl;
  outfile << endl;
  outfile.close();
  
  hOutputFile->Write() ;
  hOutputFile->Close() ;
  hOutputFile->Delete();
  
  delete data;
  
  for(int i=0; i<16; i++){
    delete mc_2012_fill_30[i];
    delete mc_2012_fill_50[i];
    delete mc_2012_fill_75[i];
    delete mc_2012_fill_90[i];
   delete mc_2012[i];
  }
  
  vector<double> values;
  
  return values;
}
示例#9
0
void makeMETPlots(){

  gStyle->SetOptFit(0);

  TChain *ch = new TChain("t");
  //ch->Add("../output/V00-02-09/highpt/LM6v2_smallTree.root");
  //ch->Add("../output/V00-02-00/LM4_baby.root");
  //ch->Add("../output/V00-02-16/highpt/LM6v2_smallTree_gen_TEMP.root");
  ch->Add("../output/V00-02-18/highpt/LM6v2_smallTree_gen.root");

  vector<TCut> metcuts;
  vector<float> metcutvals;

  metcuts.push_back(TCut("pfmet>200")); metcutvals.push_back(200);
  metcuts.push_back(TCut("pfmet>275")); metcutvals.push_back(275);

  //TCut sel("njets>=2 && ht>100 && !passz");
  TCut sel("foundPair==1 && reco1==1 && reco2==1 && ht>100 && htgen2>100 && ngenjets>=2");

  const unsigned int n = metcuts.size();

  TH1F* hpass[n];
  TH1F* hall[n];

  for( unsigned int i = 0 ; i < metcuts.size() ; ++i){

    hpass[i]   = new TH1F(Form("hpass_%i",i),Form("hpass_%i",i),25,0,500);
    hall[i]    = new TH1F(Form("hall_%i",i), Form("hall_%i",i) ,25,0,500);

    ch->Draw(Form("genmet>>hpass_%i",i),sel+metcuts.at(i));
    ch->Draw(Form("genmet>>hall_%i",i)  ,sel);

  }




  TCanvas *can = new TCanvas();
  can->cd();
  gPad->SetRightMargin(0.1);
  gPad->SetTopMargin(0.1);
  gPad->SetGridx();
  gPad->SetGridy();  
  gStyle->SetOptFit(0);

  TGraphAsymmErrors* gr[n];  
  TLegend *leg = new TLegend(0.6,0.2,0.87,0.4);
  leg->SetFillColor(0);
  leg->SetBorderSize(1);
  leg->SetTextSize(0.03);

  TF1* erf[n];

  TLine line;
  line.SetLineWidth(2);
  line.SetLineStyle(2);

  for( unsigned int i = 0 ; i < metcuts.size() ; ++i){

    //can[i] = new TCanvas(Form("can_%i",i),Form("can_%i",i),500,500);
    //can[i]->cd();
    
    // TF1* efunc = new TF1("efitf", fitf, 0, 500, 3);
    // efunc->SetParameters(1, 100, 10);
    // efunc->SetParNames("norm", "offset", "width");

    erf[i] = new TF1("efitf", fitf, 0, 500, 3);
    erf[i]->SetParameters(1, 100, 30);
    erf[i]->SetParNames("norm", "offset", "width");
    erf[i]->SetLineWidth(2);
    //erf[i]->FixParameter(0,1);

    //erf[i] = new TF1(Form("erf_%i",i),mfitf,0,400);

    //erf[i]->SetParameter(0,100*(i+1));
    //erf[i]->SetParameter(1,10);

    gr[i] = new TGraphAsymmErrors();
    if( i==0 ){
      erf[i]->SetLineColor(1);
      line.SetLineColor(1);
    }

    if( i==1 ){
      line.SetLineColor(2);
      gr[i]->SetLineColor(2);
      gr[i]->SetMarkerColor(2);
      gr[i]->SetMarkerStyle(21);
      erf[i]->SetLineColor(2);
    }
    if( i==2 ){
      gr[i]->SetLineColor(4);
      gr[i]->SetMarkerColor(4);
      gr[i]->SetMarkerStyle(25);
      erf[i]->SetLineColor(4);
    }

    leg->AddEntry(gr[i],Form("E_{T}^{miss}>%.0f GeV",metcutvals.at(i)),"p");

    gr[i]->GetXaxis()->SetRangeUser(0,500);
    gr[i]->GetXaxis()->SetTitle("generator-level E_{T}^{miss} (GeV)");
    gr[i]->GetYaxis()->SetTitle("efficiency");
    gr[i]->SetMaximum(1);
    gr[i]->BayesDivide(hpass[i],hall[i]);

    //gr[i]->Fit(efunc,"R");
    gr[i]->Fit(erf[i],"R");


    if( i==0 ) gr[i]->Draw("AP");
    else       gr[i]->Draw("sameP");

    gr[i]->GetXaxis()->SetRangeUser(0,500);
    gr[i]->GetXaxis()->SetTitle("generator-level E_{T}^{miss} (GeV)");
    gr[i]->GetYaxis()->SetTitle("efficiency");

    line.DrawLine(metcutvals.at(i),0,metcutvals.at(i),1);
    //erf[i]->Draw("same");
  }

  leg->Draw();



  TLatex *t = new TLatex();
  t->SetNDC();
  t->SetTextSize(0.05);
  t->DrawLatex(0.25,0.92,"CMS Simulation, #sqrt{s} = 7 TeV");


  can->Print("../plots/met_turnon_LM6.pdf");





}
void ratioPlots_Zxx()
{

  // llbb_Mass_reco mfJetEta_450_600 mfJetEta_250_300 lljjMass_reco mjj_HighMass_reco drll_HighMass_reco

   TString Variable = "Zxx_Mass_reco";
//   TString Variable2 = "Zbb_Mass_reco";
   TString x_title = "M_{llxx}";
   Int_t N_Rebin = 10;

   Double_t yTopLimit = 3;

   TFile *f1 = TFile::Open("/home/fynu/amertens/storage/test/MG_PY6_/output/MG_PY6_/MG_PY6v9.root");
   TH1D *h1 = (TH1D*)f1->Get(Variable);
   h1->Sumw2();
//   h1->Add((TH1D*)f1->Get(Variable2));
   h1->SetDirectory(0);
   f1->Close();

   TFile *f2 = TFile::Open("/home/fynu/amertens/storage/test/aMCNLO_PY8_/output/aMCNLO_PY8_/aMCNLO_PY8v9.root");
   TH1D *h2 = (TH1D*)f2->Get(Variable);
   h2->Sumw2();
//   h2->Add((TH1D*)f2->Get(Variable2));
   h2->SetDirectory(0);
   f2->Close();

/*
   TFile *f3 = TFile::Open("/home/fynu/amertens/storage/test/MG_PY8_/output/MG_PY8_/MG_PY8.root");
   TH1D *h3 = (TH1D*)f3->Get(Variable);
   h3->SetDirectory(0);
   f3->Close();
*/
//   h1->Sumw2();
//   h2->Sumw2();
//   h3->Sumw2();

   cout << "MG_PY6      : " << h1->Integral() << endl;
   cout << "aMC@NLO_PY8 : " << h2->Integral() << endl;


   //h1->Scale(1.0/151456.0);
   //h2->Scale(1.0/1.45192e+09);
   //h2->Scale(1./12132.9);
   h1->Scale(1.0/h1->Integral());
   h2->Scale(1.0/h2->Integral());

   h1->Sumw2();
   h2->Sumw2();



//   h3->Scale(1.0/h3->Integral());

   h1->Rebin(N_Rebin);
   h2->Rebin(N_Rebin);
//   h3->Rebin(N_Rebin);

   TH1D *h1c = h1->Clone();
   h1c->Sumw2();
   TH1D *h2c = h2->Clone();
   h2c->Sumw2();

   TH1D *h1c2 = h1->Clone();
   h1c2->Sumw2();

   h2c->Add(h1c,-1);
   h2c->Divide(h1c);


   h1->SetTitle("");
   h2->SetTitle("");
//   h3->SetTitle("");


   h1->SetLineColor(kRed);
//   h3->SetLineColor(kGreen);

   TCanvas *c1 = new TCanvas("c1","example",600,700);
   TPad *pad1 = new TPad("pad1","pad1",0,0.5,1,1);
   pad1->SetBottomMargin(0);
   gStyle->SetOptStat(0);
   pad1->Draw();
   pad1->cd();
   h2->DrawCopy();
//   h3->DrawCopy("same");
   h1->GetYaxis()->SetLabelSize(0.1);
   h1->GetYaxis()->SetRangeUser(0, 0.2);// ,yTopLimit);
   h1->GetYaxis()->SetTitleSize(0.06);
   h1->GetYaxis()->SetTitleOffset(0.7);



   h1->Draw("same");

   TLegend *leg = new TLegend(0.6,0.7,0.89,0.89);
   leg->SetLineColor(0);
   leg->SetFillColor(0);
   //leg->AddEntry(h1,"t#bar{t} uncertainty","f");
   leg->AddEntry(h1,"MG5 + PY6","l");
   leg->AddEntry(h2,"aMC@NLO + PY8","l");
//   leg->AddEntry(h3,"MG5 + PY8","l");
   leg->Draw();

   
   c1->cd();

   TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.5);
   pad2->SetTopMargin(0);
   pad2->SetBottomMargin(0.4);
   pad2->Draw();
   pad2->cd();
   pad2->SetGrid();
   h2->SetStats(0);
   h2->Divide(h1);
   //h2->SetMarkerStyle(21);
   h2->Draw("ep");
   h2->GetYaxis()->SetLabelSize(0.1);
   h2->GetYaxis()->SetRangeUser(-0.5, 2.5);// ,yTopLimit);
   h2->GetYaxis()->SetTitle("aMC@NLO+PY8 / MG5+PY6");
   h2->GetYaxis()->SetTitleSize(0.06);
   h2->GetYaxis()->SetTitleOffset(0.7);
   h2->GetXaxis()->SetLabelSize(0.1);
   h2->GetXaxis()->SetTitle(x_title);
   h2->GetXaxis()->SetTitleSize(0.16);
   h2->GetXaxis()->SetTitleOffset(0.9);
 //  Double_t matrix[4][4];
   h2->Fit("pol3","","",50.0,1200.0);
   TF1 *ratio = h2->GetFunction("pol3");
   TVirtualFitter *fitter = TVirtualFitter::GetFitter();
   TMatrixD matrix(4,4,fitter->GetCovarianceMatrix());
   Double_t errorPar00 = fitter->GetCovarianceMatrixElement(0,0);
   Double_t errorPar11 = fitter->GetCovarianceMatrixElement(1,1);
   Double_t errorPar22 = fitter->GetCovarianceMatrixElement(2,2);
   Double_t errorPar33 = fitter->GetCovarianceMatrixElement(3,3);
//   c1->cd();

   matrix.Print();

   //const TMatrixDSym m = matrix;
   const TMatrixDEigen eigen(matrix);
   const TMatrixD eigenVal = eigen.GetEigenValues();
   const TMatrixD V = eigen.GetEigenVectors(); 

   cout << "V" << endl;

   V.Print();

   cout << "eigenVal" << endl;

   eigenVal.Print();



   cout << "Recomputed diag" << endl;

   //const TMatrixD Vt(TMatrixD::kTransposed,V);
   //const TMatrixD Vinv = V.Invert();
   const TMatrixD Vt(TMatrixD::kTransposed,V);
   //cout << "V-1" << endl;
   //Vinv.Print();
   cout << "Vt" << endl;
   Vt.Print();

   const TMatrixD VAVt = Vt*matrix*V;
   VAVt.Print();


   const TVectorD FittedParam(4);
   FittedParam(0) = fitter->GetParameter(0);
   FittedParam(1) = fitter->GetParameter(1);
   FittedParam(2) = fitter->GetParameter(2);
   FittedParam(3) = fitter->GetParameter(3);
   FittedParam.Print();


   //const TVectorD FittedParamNB(4);
   const TVectorD PNb = V*FittedParam;
   cout << "Pnb" << endl;
   PNb.Print();
  

   cout << " Generating other parameters values " << endl;

   cout <<" V " << V(0,0) << endl;

   TRandom3 r;
   const TVectorD NewP(4);

   TH1D *hist100 = new TH1D("h100","h100",200,-5,5);
   TH1D *hist200 = new TH1D("h200","h200",200,-5,5);
   TH1D *hist400 = new TH1D("h400","h400",200,-5,5);
   TH1D *hist600 = new TH1D("h600","h600",100,-5,5);
   TH1D *hist800 = new TH1D("h800","h800",100,-5,5);
   TH1D *hist1000 = new TH1D("h1000","h1000",100,-5,5);

   TH1D *histp0 = new TH1D("p0","p0",100,-0.2,0.3);
   TH1D *histp1 = new TH1D("p1","p1",100,0.0,0.01);
   TH1D *histp2 = new TH1D("p2","p2",100,-0.00001,0);
   TH1D *histp3 = new TH1D("p3","p3",100,0,0.000000002);



   for (Int_t i = 0; i< 500; i++){
     NewP(0) = r.Gaus(PNb(0),sqrt(eigenVal(0,0)));
     NewP(1) = r.Gaus(PNb(1),sqrt(eigenVal(1,1)));
     NewP(2) = r.Gaus(PNb(2),sqrt(eigenVal(2,2)));
     NewP(3) = r.Gaus(PNb(3),sqrt(eigenVal(3,3)));
     //NewP.Print();

     //FittedParam.Print();

     const TVectorD NewP2 = Vt*NewP;
     //NewP2.Print();

     histp0->Fill(NewP2(0));
     histp1->Fill(NewP2(1));
     histp2->Fill(NewP2(2));
     histp3->Fill(NewP2(3));



     TF1 *newFit=new TF1("test","[0]+x*[1]+[2]*pow(x,2)+[3]*pow(x,3)",0,1400);
     newFit->SetParameters(NewP2(0),NewP2(1),NewP2(2),NewP2(3));
     newFit->SetLineColor(kBlue);

     Double_t area=0;
     for(Int_t it=1; it < 16; it++){
       //cout << "bin : " << it << " " << h1c2->GetBinContent(it) << endl;
       area += h1c2->GetBinContent(it)*newFit->Eval(100*it+50);
       }
   
     //newFit->Draw("same");
     //cout <<"val: " << newFit->Eval(200) << endl;
     hist100->Fill(newFit->Eval(100)/area);
     hist200->Fill(newFit->Eval(200)/area);
     hist400->Fill(newFit->Eval(400)/area);
     hist600->Fill(newFit->Eval(600)/area);
     hist800->Fill(newFit->Eval(800)/area);
     hist1000->Fill(newFit->Eval(1000)/area);
     }

   c1->cd();
   TCanvas *c2 = new TCanvas("c2","c2",1000,1000);
   c2->cd();
   c2->Divide(3,2);
   c2->cd(1);
   hist100->Draw();
   c2->cd(2);
   hist200->Draw();
   c2->cd(3);
   hist400->Draw();
   c2->cd(4);
   hist600->Draw();
   c2->cd(5);
   hist800->Draw();
   c2->cd(6);
   hist1000->Draw();



Double_t m_100,m_200,m_400,m_600,m_800,m_1000;
Double_t s_100,s_200,s_400,s_600,s_800,s_1000;

hist100->Fit("gaus","","",0.3,1.2);
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
m_100 = fitter->GetParameter(1);
s_100 = fitter->GetParameter(2);

hist200->Fit("gaus","","",0.5,1.2);
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
m_200 = fitter->GetParameter(1);
s_200 = fitter->GetParameter(2);

hist400->Fit("gaus","","",0.8,1.2);
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
m_400 = fitter->GetParameter(1);
s_400 = fitter->GetParameter(2);

hist600->Fit("gaus","","",0.8,1.3);
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
m_600 = fitter->GetParameter(1);
s_600 = fitter->GetParameter(2);

hist800->Fit("gaus","","",0.5,2);
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
m_800 = fitter->GetParameter(1);
s_800 = fitter->GetParameter(2);

hist1000->Fit("gaus","","",0.5,2.5);
TVirtualFitter *fitter = TVirtualFitter::GetFitter();
m_1000 = fitter->GetParameter(1);
s_1000 = fitter->GetParameter(2);


Double_t x[6],y[6],ym[6],yup[6],ydown[6];
x[0]=100; x[1]=200; x[2]=400;x[3]=600; x[4]=800; x[5]=1000;
yup[0]=ratio->Eval(100)+s_100;
yup[1]=ratio->Eval(200)+s_200;
yup[2]=ratio->Eval(400)+s_400;
yup[3]=ratio->Eval(600)+s_600;
yup[4]=ratio->Eval(800)+s_800;
yup[5]=ratio->Eval(1000)+s_1000;
ydown[0]=ratio->Eval(100)-s_100;
ydown[1]=ratio->Eval(200)-s_200;
ydown[2]=ratio->Eval(400)-s_400;
ydown[3]=ratio->Eval(600)-s_600;
ydown[4]=ratio->Eval(800)-s_800;
ydown[5]=ratio->Eval(1000)-s_1000;

y[0]=1+s_100/ratio->Eval(100);
y[1]=1+s_200/ratio->Eval(200);
y[2]=1+s_400/ratio->Eval(400);
y[3]=1+s_600/ratio->Eval(600);
y[4]=1+s_800/ratio->Eval(800);
y[5]=1+s_1000/ratio->Eval(1000);

ym[0]=-s_100/m_100;
ym[1]=-s_200/m_200;
ym[2]=-s_400/m_400;
ym[3]=-s_600/m_600;
ym[4]=-s_800/m_800;
ym[5]=-s_1000/m_1000;


TGraph* g = new TGraph(6,x,y);
TGraph* gm = new TGraph(6,x,ym);
TGraph* gup = new TGraph(6,x,yup);
TGraph* gdown = new TGraph(6,x,ydown);


TCanvas *c3 = new TCanvas("c3","c3",1000,1000);
c3->cd();

//gup->Draw("AC*");
//gdown->Draw("C*");
g->Draw("AC*");

gPad->SetBottomMargin(0.2);
gPad->SetLeftMargin(0.2);
gStyle->SetOptStat(0);

g->GetXaxis()->SetTitle("M_{Zbb}");
g->GetXaxis()->SetRangeUser(50,1100);
g->GetYaxis()->SetLabelSize(0.06);
g->GetYaxis()->SetTitle("Uncertainty");
g->GetYaxis()->SetTitleSize(0.06);
g->GetYaxis()->SetTitleOffset(1.4);
g->GetXaxis()->SetLabelSize(0.06);
g->GetXaxis()->SetTitleSize(0.06);
g->GetXaxis()->SetTitleOffset(1);
g->GetYaxis()->SetNdivisions(5);

TFile f("syst_zxx.root","recreate");
g->Write();
f.Close();


//gm->Draw("C*");
//g->SetMaximum(1);
//g->SetMinimum(-1);
//h2c->Draw("same");


TH1D *h22=h2->Clone();

TCanvas *c5 =  new TCanvas("c5","c5",1000,1000);

gPad->SetBottomMargin(0.2);
gPad->SetLeftMargin(0.2);
gStyle->SetOptStat(0);

h22->Draw();
h22->GetXaxis()->SetRangeUser(50,1100);
h22->GetYaxis()->SetLabelSize(0.06);
h22->GetYaxis()->SetTitleSize(0.06);
h22->GetYaxis()->SetTitleOffset(1.4);
h22->GetXaxis()->SetLabelSize(0.06);
h22->GetXaxis()->SetTitleSize(0.06);
h22->GetXaxis()->SetTitleOffset(1);

ratio->SetLineColor(kRed);
ratio->Draw("same");

gup->Draw("C");
gdown->Draw("C");


TLegend *leg = new TLegend(0.6,0.7,0.89,0.89);
leg->SetLineColor(0);
leg->SetFillColor(0);
leg->AddEntry(h22,"aMC@NLO / MG5","lep");
leg->AddEntry(ratio,"best fit","l");
leg->AddEntry(gup,"Syst Error (#pm 1 #sigma)","l");
leg->Draw();



TCanvas *c4 = new TCanvas("c4","c4",1000,1000);
c4->Divide(2,2);
c4->cd(1);
histp0->Draw();
c4->cd(2);
histp1->Draw();
c4->cd(3);
histp2->Draw();
c4->cd(4);
histp3->Draw();


}
示例#11
0
//================================================
void eventBinning(const Int_t save = 0)
{
  TH1F *hVtxZ = (TH1F*)f->Get(Form("mhVertexZ_%s",trigName[kTrigType]));
  c = draw1D(hVtxZ,"",kFALSE,kFALSE);
  for(int i=0; i<19; i++)
    {
      double value = -100 + i*10 + 10;
      double height = hVtxZ->GetBinContent(hVtxZ->FindFixBin(value));
      TLine *line = GetLine(value,0,value,height,2,1,1);
      line->Draw();
    }
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_EventMixing/%sVertexZ_Binning.pdf",run_type,run_cfg_name.Data()));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_EventMixing/%sVertexZ_Binning.png",run_type,run_cfg_name.Data()));
    }

  TH1F *hgRefMultCorr = (TH1F*)f->Get(Form("mhgRefMultCorr_%s",trigName[kTrigType]));
  c = draw1D(hgRefMultCorr,"",kTRUE,kFALSE);
  //double bounds[9] = {472,401,283,193,126,77,44,23,11};
  double bounds[16] = {11,16,23,32,44,59,77,99,126,157,193,235,283,338,401,472};
  for(int i=0; i<16; i++)
    {
      double value = bounds[i];
      double height = hgRefMultCorr->GetBinContent(hgRefMultCorr->FindFixBin(value));
      TLine *line = GetLine(value,0,value,height,2,1,1);
      line->Draw();
    }
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_EventMixing/%sgRefMult_Binning.pdf",run_type,run_cfg_name.Data()));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_EventMixing/%sgRefMult_Binning.png",run_type,run_cfg_name.Data()));
    }

  // centrality
  TH1F *hgRefMult = (TH1F*)f->Get(Form("mhgRefMult_%s",trigName[kTrigType]));
  hgRefMult->SetLineColor(2);
  c = draw1D(hgRefMult,"",kTRUE,kFALSE);
  hgRefMultCorr->Draw("sames HIST");
  TLegend *leg = new TLegend(0.15,0.3,0.4,0.5);
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->SetTextSize(0.04);
  leg->AddEntry(hgRefMult,"Raw gRefMult","L");
  leg->AddEntry(hgRefMultCorr,"Corrected gRefMult","L");
  leg->Draw();
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_EventMixing/%sgRefMult.pdf",run_type,run_cfg_name.Data()));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_EventMixing/%sgRefMult.png",run_type,run_cfg_name.Data()));
    }


  TH1F *hCentrality = (TH1F*)f->Get(Form("mhCentrality_%s",trigName[kTrigType]));
  c = draw1D(hCentrality,"",kTRUE,kFALSE);
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_EventMixing/%sCentrality.pdf",run_type,run_cfg_name.Data()));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_EventMixing/%sCentrality.png",run_type,run_cfg_name.Data()));
    }

  // event plane
  TH2F *hExcVsIncRawEP = (TH2F*)f->Get(Form("mhExcVsIncRawEP_%s",trigName[kTrigType]));
  c = draw2D(hExcVsIncRawEP);

  TH1F *hEventPlane = (TH1F*)f->Get(Form("mhEventPlane_%s",trigName[kTrigType]));
  c = draw1D(hEventPlane,"",kFALSE,kFALSE);
}
示例#12
0
文件: plotv2.C 项目: XuQiao/HI
void plotv2(){
    const int ncent = 6;
    const int npt = 25;
    int scale = 1;
    int centbin[ncent+1] = {0,5,10,20,40,60,100};
    gStyle->SetOptFit(kFALSE);
    gStyle->SetOptStat(kFALSE);

    //-----------------TGraphs--------------------------
//TGraphErrors* gr1[ncent];
//TGraphErrors* gr2[ncent];
TGraphErrors* gr[ncent];
//TGraphErrors* grsub1[ncent];
//TGraphErrors* grsub2[ncent];
TGraphErrors* grsub[ncent];
TGraphErrors* grF[ncent];
    
TGraphErrors *grP[ncent];

    for(int icent=0;icent<ncent;icent++){
    
    gr[icent] = new TGraphErrors(Form("v2_cent%d.dat",icent),"%lg %lg %lg");
    grsub[icent] = new TGraphErrors(Form("v2_cent%d_scale%d.dat",icent,scale));
    grF[icent] = new TGraphErrors(Form("../../Ridge3corrfvtx/20GeV/v2_cent%d.dat",icent),"%lg %lg %lg");

//-----------plotting results-----------------------------------------------------
    if(icent<0){
//    grP[icent] = new TGraphErrors(Form("v2_00_%d_BBCS.dat",icent),"%lg %lg %lg");
    grP[icent] = new TGraphErrors(Form("v2_00_%d_FVTX1S.dat",icent),"%lg %lg %lg");
    grP[icent]->SetName(Form("grP_%d",icent));
    grP[icent]->SetMarkerSize(1.2);
    grP[icent]->SetMarkerStyle(20);
    grP[icent]->SetMarkerColor(1);
    grP[icent]->SetLineColor(1);
 }
    TH1D* h = new TH1D(Form("h_%d",icent),"",100,0,5);
    h->GetXaxis()->SetTitle("p_{T} (GeV/c)");
    h->GetYaxis()->SetTitle("v_{2}");
    h->GetXaxis()->SetRangeUser(0,3.5);
    h->GetYaxis()->SetRangeUser(0,0.25);

 float ptv2[npt];
  float eptv2[npt], sptv2[npt];
  float v2data[npt], ev2data[npt], sv2data[npt], asv2data1[npt];
  int npoints = 11;
  ifstream finv2("v2_pt_dAu_00_05_sys.dat");

  //Elliptic flow
  for(int i=0; i<npoints; i++)
    {
      eptv2[i]=0;
      sptv2[i]=0.05;
      finv2>>ptv2[i]>>v2data[i]>>ev2data[i]>>sv2data[i];//>>asv2data1[i];
    }
  finv2.close();

  TGraphErrors *grP0 = new TGraphErrors(npoints, ptv2, v2data, eptv2, ev2data);
  grP0->SetMarkerStyle(23);
  grP0->SetMarkerColor(2);
  TF1 *fun = new TF1("fun","pol4",0,5);
 
  /*
  grP[icent]->Fit("fun","Q0");
    TCanvas *c1 = new TCanvas("c1","",500,500);
    h->Draw();
    TLegend *leg = new TLegend(0.2,0.6,0.4,0.8);
    leg->SetBorderSize(0);
    leg->SetFillStyle(0);
    leg->SetTextSize(0.04);
    if(icent==0){
    leg->AddEntry(grP,"Event plane","P");
    leg->AddEntry(fun,"pol 4 fit","L");
    }
    leg->AddEntry(gr1[icent],"use cnt-bbc","P");
    leg->AddEntry(gr2[icent],"use cnt-fvtx","P");
    leg->AddEntry(gr[icent],"use 3-sub","P");
    leg->Draw("same");
    grP[icent]->SetMarkerStyle(20);
    grP[icent]->SetMarkerColor(1);
    gr1[icent]->SetMarkerSize(1.2);
    gr1[icent]->SetMarkerStyle(21);
    gr1[icent]->SetMarkerColor(4);
    gr1[icent]->SetLineColor(4);
    gr2[icent]->SetMarkerSize(1.2);
    gr2[icent]->SetMarkerStyle(20);
    gr2[icent]->SetMarkerColor(2);
    gr2[icent]->SetLineColor(2);
    gr[icent]->SetMarkerSize(1.2);
    gr[icent]->SetMarkerStyle(24);
    gr[icent]->SetMarkerColor(1);
    gr[icent]->SetLineColor(1);
    gr1[icent]->Draw("Psame");
    gr2[icent]->Draw("Psame");
    gr[icent]->Draw("Psame");

//  0-5%
  if(icent==0){
 
  fun->Draw("same");
      for(int i=0; i<npoints; i++)
	{
	  double px1 = ptv2[i]-0.05;
	  double py1 = v2data[i]+sv2data[i];
	  double px2 = ptv2[i]+0.05;
	  double py2 = v2data[i]-sv2data[i];
	  TBox *boxv2 = new TBox(px1,py1,px2,py2);
	  boxv2->SetFillColor(kBlack);
	  boxv2->SetFillStyle(0);
	  boxv2->SetLineColor(kBlack);
	  boxv2->SetLineWidth(1);
	  boxv2->Draw("LSAME");
    }
 
    grP[icent]->Draw("Psame");
  }
    c1->Print(Form("v22pc_cent%d_scale%d.png",icent,scale));

    TCanvas *c2 = new TCanvas("c2","",500,500);
    h->Draw();
    TLegend *leg = new TLegend(0.2,0.6,0.4,0.8);
    leg->SetBorderSize(0);
    leg->SetFillStyle(0);
    leg->SetTextSize(0.04);
    //leg->AddEntry(grP,"Preliminary","P");
    //leg->AddEntry(fun,"pol 4 fit","L");
    leg->AddEntry(gr1[icent],"use cnt-bbc","P");
    leg->AddEntry(grsub1[icent],"use cnt-bbc subtracted","P");
    //leg->AddEntry(gr,"use 3-sub","P");
    leg->Draw();
    gr1[icent]->SetMarkerSize(1.2);
    gr1[icent]->SetMarkerStyle(21);
    gr1[icent]->SetMarkerColor(4);
    gr1[icent]->SetLineColor(4);
    grsub1[icent]->SetMarkerSize(1.2);
    grsub1[icent]->SetMarkerStyle(21);
    grsub1[icent]->SetMarkerColor(2);
    grsub1[icent]->SetLineColor(2);
    gr1[icent]->Draw("Psame");
    grsub1[icent]->Draw("Psame");
  if(icent==0){
  fun->Draw("same");
      for(int i=0; i<npoints; i++)
	{
	  double px1 = ptv2[i]-0.05;
	  double py1 = v2data[i]+sv2data[i];
	  double px2 = ptv2[i]+0.05;
	  double py2 = v2data[i]-sv2data[i];
	  TBox *boxv2 = new TBox(px1,py1,px2,py2);
	  boxv2->SetFillColor(kBlack);
	  boxv2->SetFillStyle(0);
	  boxv2->SetLineColor(kBlack);
	  boxv2->SetLineWidth(1);
	  boxv2->Draw("LSAME");
    }
    grP->Draw("Psame");
  }
    c2->Print(Form("v2cntbbc_cent%d_scale%d.png",icent,scale));

    TCanvas *c3 = new TCanvas("c3","",500,500);
    h->Draw();
    TLegend *leg = new TLegend(0.2,0.6,0.4,0.8);
    leg->SetBorderSize(0);
    leg->SetFillStyle(0);
    leg->SetTextSize(0.04);
    leg->AddEntry(gr1[icent],"use cnt-fvtx","P");
    leg->AddEntry(grsub1[icent],"use cnt-fvtx subtracted","P");
    leg->Draw();
    gr2[icent]->SetMarkerSize(1.2);
    gr2[icent]->SetMarkerStyle(21);
    gr2[icent]->SetMarkerColor(4);
    gr2[icent]->SetLineColor(4);
    grsub2[icent]->SetMarkerSize(1.2);
    grsub2[icent]->SetMarkerStyle(21);
    grsub2[icent]->SetMarkerColor(2);
    grsub2[icent]->SetLineColor(2);
    gr2[icent]->Draw("Psame");
    grsub2[icent]->Draw("Psame");
  if(icent==0){
  fun->Draw("same");
      for(int i=0; i<npoints; i++)
	{
	  double px1 = ptv2[i]-0.05;
	  double py1 = v2data[i]+sv2data[i];
	  double px2 = ptv2[i]+0.05;
	  double py2 = v2data[i]-sv2data[i];
	  TBox *boxv2 = new TBox(px1,py1,px2,py2);
	  boxv2->SetFillColor(kBlack);
	  boxv2->SetFillStyle(0);
	  boxv2->SetLineColor(kBlack);
	  boxv2->SetLineWidth(1);
	  boxv2->Draw("LSAME");
    }
    grP->Draw("Psame");
  }
    c3->Print(Form("v2cntfvtx_cent%d_scale%d.png",icent,scale));
 */   
    TCanvas *c4 = new TCanvas(Form("c4_%d",icent),"",500,500);
    h->Draw();
    TLegend *leg = new TLegend(0.2,0.6,0.4,0.8);
    leg->SetBorderSize(0);
    leg->SetFillStyle(0);
    leg->SetTextSize(0.04);
    leg->AddEntry(gr[icent],"use 3-sub cnt-fvtxs-bbcs","P");
    leg->AddEntry(grF[icent],"use 3-sub cnt-fvtxs-fvtxn","P");
    if(icent<0)
    leg->AddEntry(grP[icent],"use FVTXS EP","P");
    //leg->AddEntry(grsub1[icent],"use 3-sub subtracted","P");
    leg->Draw("same");
    gr[icent]->SetMarkerSize(1.2);
    gr[icent]->SetMarkerStyle(21);
    gr[icent]->SetMarkerColor(4);
    gr[icent]->SetLineColor(4);
   // grsub[icent]->SetMarkerSize(1.2);
   // grsub[icent]->SetMarkerStyle(21);
   // grsub[icent]->SetMarkerColor(2);
   // grsub[icent]->SetLineColor(2);
    grF[icent]->SetMarkerSize(1.2);
    grF[icent]->SetMarkerStyle(21);
    grF[icent]->SetMarkerColor(2);
    grF[icent]->SetLineColor(2);
    gr[icent]->Draw("Psame");
    //grsub[icent]->Draw("Psame");
    grF[icent]->Draw("Psame");
    if(icent<0){
      /*
  fun->Draw("same");
      for(int i=0; i<npoints; i++)
	{
	  double px1 = ptv2[i]-0.05;
	  double py1 = v2data[i]+sv2data[i];
	  double px2 = ptv2[i]+0.05;
	  double py2 = v2data[i]-sv2data[i];
	  TBox *boxv2 = new TBox(px1,py1,px2,py2);
	  boxv2->SetFillColor(kBlack);
	  boxv2->SetFillStyle(0);
	  boxv2->SetLineColor(kBlack);
	  boxv2->SetLineWidth(1);
	  boxv2->Draw("LSAME");
    }
    */
   // grP0->Draw("Psame");
    grP[icent]->Draw("Psame");
  }
    c4->Print(Form("v23sub_cent%d_scale%d.png",icent,scale));
/*
    TCanvas *c5 = new TCanvas("c5","",500,500);
    h->Draw();
    TLegend *leg = new TLegend(0.2,0.6,0.4,0.8);
    leg->SetBorderSize(0);
    leg->SetFillStyle(0);
    leg->SetTextSize(0.04);
    leg->AddEntry(grsub1[icent],"use cnt-bbc subtracted","P");
    leg->AddEntry(grsub2[icent],"use cnt-fvtx subtracted","P");
    leg->AddEntry(grsub[icent],"use 3-sub subtracted","P");
    leg->Draw();
    grsub1[icent]->SetMarkerSize(1.2);
    grsub1[icent]->SetMarkerStyle(21);
    grsub1[icent]->SetMarkerColor(4);
    grsub1[icent]->SetLineColor(4);
    grsub2[icent]->SetMarkerSize(1.2);
    grsub2[icent]->SetMarkerStyle(20);
    grsub2[icent]->SetMarkerColor(2);
    grsub2[icent]->SetLineColor(2);
    grsub[icent]->SetMarkerSize(1.2);
    grsub[icent]->SetMarkerStyle(24);
    grsub[icent]->SetMarkerColor(1);
    grsub[icent]->SetLineColor(1);
    grsub1[icent]->Draw("Psame");
    grsub2[icent]->Draw("Psame");
    grsub[icent]->Draw("Psame");

  if(icent==0){
  fun->Draw("same");
      for(int i=0; i<npoints; i++)
	{
	  double px1 = ptv2[i]-0.05;
	  double py1 = v2data[i]+sv2data[i];
	  double px2 = ptv2[i]+0.05;
	  double py2 = v2data[i]-sv2data[i];
	  TBox *boxv2 = new TBox(px1,py1,px2,py2);
	  boxv2->SetFillColor(kBlack);
	  boxv2->SetFillStyle(0);
	  boxv2->SetLineColor(kBlack);
	  boxv2->SetLineWidth(1);
	  boxv2->Draw("LSAME");
    }
    grP->Draw("Psame");
  }
    c5->Print(Form("v22pc_subtract_cent%d_scale%d.png",icent,scale));
    */
}
}
void displayMultipleFiles(std::string inputTextFile, 
			  std::string var, 
			  std::string xtitle="", std::string ytitle="",
			  std::string output="test", bool logScale=false)
{
  
  setTDRStyle();
  gStyle->SetOptStat(0);

  
  FILE *fTable = fopen(inputTextFile.data(),"r");
   
  int flag=1;   

  std::vector<std::string> dataFile;
  std::vector<std::string> legendName;

  char filename[300];

  while (flag!=-1){
    // first reading input file
    flag=fscanf(fTable,"%s",filename);
    std::string tempFile = filename;

    flag=fscanf(fTable,"%s",filename);
    std::string tempLegend = filename;

    if (flag!=-1) {
      dataFile.push_back(tempFile);
      cout << "Reading " << tempFile.data() << endl;
      legendName.push_back(tempLegend);
      cout << "Legend is " << tempLegend.data() << endl;
    }
  }	 

  int nfile=dataFile.size();
	
  cout << "There are " << nfile << " files to compare" << endl;

  TH1F* h[20];
  TFile* f[20];

  const int NMAXFILE=10;

  if(nfile > NMAXFILE){
    cout << "Too many files!!" << endl;
    return;
  }

  TCanvas* c1 = new TCanvas("c1","",500,500);
  if(logScale)c1->SetLogy(1);
  else c1->SetLogy(0);

  float max=-9999.0;
  int maxHisto=-1;
  
  for(int i=0; i < nfile; i++){
    f[i] = TFile::Open(dataFile[i].data());
    h[i] = (TH1F*)(f[i]->Get(var.data()));
    h[i]->SetXTitle(xtitle.data());  
    h[i]->SetYTitle(ytitle.data());  
    h[i]->GetYaxis()->SetDecimals();
    h[i]->GetYaxis()->SetNdivisions(5);
    h[i]->GetXaxis()->SetNdivisions(5);
    h[i]->SetLineColor(1+i);
    h[i]->SetMarkerColor(1+i);
    h[i]->SetMarkerSize(1);
    h[i]->SetMarkerStyle(21);
    h[i]->Rebin(2);

    cout << "h[" << i << "] mean = " << h[i]->GetMean() << " and width = " << h[i]->GetRMS() << 
      " and entries = " << h[i]->GetEntries() << " and integral = " << 
      h[i]->Integral() << endl;
    

    float scale = 1.0/(float)h[i]->Integral();
    h[i]->Sumw2();
    h[i]->Scale(scale);

    float max1   = h[i]->GetBinError(h[i]->GetMaximumBin()) + h[i]->GetMaximum();

    if(max1>max){max = max1; maxHisto=i;}
  }

//   h[maxHisto]->SetMaximum(0.15);
  h[maxHisto]->SetMaximum(0.1);
  h[maxHisto]->Draw("histe");
  for(int i=0; i<nfile; i++)h[i]->Draw("histesame");
    

  TLegend* leg = new TLegend(0.31,0.425,0.51,0.85);
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->SetTextSize(0.04);
  leg->SetBorderSize(0);
  leg->SetHeader("|y_{B}| < 0.5");
  for(int i=0; i< nfile; i++)
    leg->AddEntry(h[i], legendName[i].data());
  leg->Draw("same");

  std::string outputFile;
  std::string psname = output;
  outputFile = psname + ".eps";
  c1->Print(outputFile.data());
  outputFile = psname + ".gif";
  c1->Print(outputFile.data());
}
示例#14
0
void makePlots (string configFilePath){
  if ((  inputRootFileNum.size() > 0 )) 
    {
      for (int i=0; i<numHistos; i++) 
        {
          double y_max = 0.0;	 
          TCanvas *c = new TCanvas(theHistNameStrings.at(i).c_str(), "", 81,58,500,602);
 
          TH1* h_num;        // histograms for Numerator
          TH1* h_den;        // histohrams for Denominator
          int whichHisto = 0;

	  TMultiGraph *mg = new TMultiGraph();
          for (int j=0;j<inputRootFileNum.size();j++)
	    {
             whichHisto=j*numHistos; 
	      
	      int a = 0;
	      bool foundHisto = false;
	      if (theHistNameStrings.at(i) == theHistNameStrings.at(i+whichHisto)) 
		{
		  foundHisto=true; 
		  a=i;
		}
	      else 
		{
		  for (a = 0; a < numHistos; a++)
		    {
		      if (theHistNameStrings.at(i) == theHistNameStrings.at(a+whichHisto))
			{
			  foundHisto = true;
			  break;
			}
		    }
		}
	      //-----------------------------------------------------------
	      string hist2name = listHistosNum->At(a+whichHisto)->GetName();
	      if (foundHisto == true)
		{
                  h_num = (TH1*)listHistosNum->At(i+whichHisto);
                  h_den = (TH1*)listHistosDen->At(a+whichHisto);

                  TH1F* H_bins_num;
                  TH1F* H_bins_den;
                  int id = 0;
                  for (int k = 0; k < inputXtitle.size(); k++)
                   {
                     if (hist2name == inputHistoName.at(k)){
                      id=k;
                    }
                   }
                  if (inputdifferentBinSize.at(id)==1){
                     int Nbins = h_num->GetXaxis()->GetNbins();
                     int arrayD = (int*)inputNbins.at(id);
                     float *BINS = new float [arrayD];
                     for (int b = 0; b <= arrayD; b++ )
                       {
                          if (b < (arrayD-1))
                           {
                             BINS[b] = (float)b*(h_num->GetXaxis()->GetBinWidth(b));
                           }
                          else {
                             BINS[b] = (float)inputBinSize.at(id);
                          }
                       }
                     H_bins_num = new TH1F("h_NUM", "h_NUM", inputNbinMax.at(id), BINS);
                     H_bins_den = new TH1F("h_DEN", "h_DEN", inputNbinMax.at(id), BINS);
                     for (int b = 0; b <= (Nbins+1); b++ )
                       {
                         H_bins_num->SetBinContent(b, h_num->GetBinContent(b));
                         H_bins_den->SetBinContent(b, h_den->GetBinContent(b));
                       }
                  }

                  if (inputdifferentBinSize.at(id)==1){
                     TGraphAsymmErrors* gr1 = new TGraphAsymmErrors( H_bins_num, H_bins_den, "b(1,1) mode" );
                  } else{
                    cout << "h_num "<<h_num->GetXaxis()->GetNbins() << "  h_den "<<h_den->GetXaxis()->GetNbins()<<endl;
                    cout << "h_num "<<h_num->Integral() << "  h_den "<<h_den->Integral()<<endl;
                    TGraphAsymmErrors* gr1 = new TGraphAsymmErrors( h_num, h_den, "b(1,1) mode" );
                  }
		  int setcolor = inputColor.at(j);
		  int marker   = inputMarkerStyle.at(j);
                  string processlegend = (inputLegend.at(j)).c_str();
                  gr1->SetMarkerStyle(marker);
                  gr1->SetMarkerColor(setcolor);
                  gr1->SetTitle(processlegend.c_str());
                  gr1->SetFillStyle(0);
                  mg->SetTitle(hist2name.c_str());
                  mg->Add(gr1);
		}// close if (foundHisto)
 
	      c->cd();
 	      c->SetGrid(); 
	    } // close for loop inputRootFile

          mg->Draw("APsame");
          for (int k = 0; k < inputXtitle.size(); k++)
           {
              if (hist2name == inputHistoName.at(k))
               {
                 mg->GetXaxis()->SetTitle((inputXtitle.at(k)).c_str());
                 mg->GetYaxis()->SetTitle((inputYtitle.at(k)).c_str());
                 mg->GetXaxis()->SetTitleSize(0.05);
                 mg->GetYaxis()->SetTitleSize(0.05);
                 mg->SetMaximum((float)inputYrangeMax.at(k));
               }
           }
          c->Update();
          TLegend* legend = c->BuildLegend(0.55,0.8,0.90,0.94);
          //TLegend *legend = new TLegend(0.2, 0.85-.035*inputLegend.size(), 0.5, 0.90,NULL,"brNDC");
          legend->SetTextFont(42);
          legend->SetLineColor(1);
          legend->SetLineStyle(1);
          legend->SetLineWidth(1);
          legend->SetFillColor(0);
          legend->SetFillStyle(1001);
          legend->SetBorderSize(0);
          legend->SetFillColor(kWhite);

	  TFile *hfile = (TFile*)gROOT->FindObject(HistosOutputRootFile.c_str());
	  if (hfile) {hfile->Close();}
	  hfile = new TFile(HistosOutputRootFile.c_str(),"UPDATE");

          for (int o = 0; o < inputHistoName.size(); o++)
             {
                if ( c->GetName() == inputHistoName.at(o) )
                  {
                     string save = configFilePath+"/"+inputHistoName.at(o)+".pdf";  
                     c->SaveAs(save.c_str());
                     c->Write();    
                     break;
                  }
             }

	  hfile->Close();
          c->Close();
	  
	}  // close foor loop numHistos     
      
    } // close if numHistos % inputRootFile.size() == 0
} // close  makePlots function
fit_info* do_fit(TH1D *hSelection, TH1D *hControl, TH1D *hConversions, double theHT, double thestep) {

  //  gSystem->Load("libRooFit"); using namespace RooFit;

  double hi=3.;

  RooRealVar x("x","alphaT",0.,hi);
  
  RooRealVar alpha("nconv","a coefficient",0.);//100.,0.,100000.) ;
  RooRealVar fakes("nfakes","b coefficient",1000.,0.,100000.) ;
  RooFormulaVar nBkg("N_bkg","","nconv+nfakes",RooArgList(alpha,fakes));

  RooDataHist temp1("temp1","temp1",x,hConversions);//p_conv);
  RooDataHist temp2("temp2","temp2",x,hControl);//p_ctrl);

  RooHistPdf tConv("tConv","Template for conversions",x,temp1);
  RooHistPdf tFakes("tFakes","Template for fakes",x,temp2);

  // Composite Model PDF
  RooAddPdf bkg("bkg","bkg PDF",RooArgList(tConv, tFakes),RooArgList(alpha,fakes));
  RooAddPdf model("model","bkg PDF",RooArgList(tConv, tFakes),RooArgList(alpha,fakes));
  
  // Data
  RooDataHist data("data","data",x,hSelection);
  
  // Fitting
  //  double fitH=GetMinimum(hSelection,0.55,3.);
  RooFitResult *fitr=0;// = bkg.fitTo(data,Range(0.3,fitH),Minos(kTRUE),Extended(kTRUE), Save(kTRUE));

  // Signal region for prediction
  double cut=0.55;
  x.setRange("selection",cut,hi);
 
  Int_t low=hSelection->GetXaxis()->FindBin(cut);
  Int_t high=hSelection->GetXaxis()->FindBin(hi);


  fit_info* fit=new fit_info();
  fit->inom=hSelection->Integral(0,high);
    //data.createIntegral(x,NormSet(x),Range("lowsel"))->getVal();
    //hSelection->Integral(0,low);
  //fit->nom=data.createIntegral(x,NormSet(x),Range("selection"))->getVal(); 
  fit->nom=hSelection->Integral(low,high);
    //nObserved;

  fit->ictrl=hControl->Integral(0,high);
  fit->ctrl=hControl->Integral(low,high);

  fit->val1=alpha.getVal();
  fit->val2=fakes.getVal();
  fit->err1=alpha.getError();
  fit->err2=fakes.getError();

  /* fit->corr1=fit->val1*factor1; */
  /* fit->corr2=fit->val2*factor2; */
  /* fit->err1_corr=fit->err1*factor1; */
  /* fit->err2_corr=fit->err2*factor2; */

  /* fit->icorr1=fit->val1*ifactor1; */
  /* fit->icorr2=fit->val2*ifactor2; */
  /* fit->ierr1_corr=fit->err1*ifactor1; */
  /* fit->ierr2_corr=fit->err2*ifactor2; */

  //  fit->gcor12 = fitr->correlation(alpha,fakes);

  // Plotting
  setStyles();

  TString labelName="Predicted = ";
  //  labelName+=(int)nPredicted;
  labelName+=" +/- ";
  //  labelName+=(int)comb_error;

  TString canvasName="c";
  canvasName+=theHT;

  TCanvas *c = new TCanvas("cfit"+canvasName,"");

  TLegend *leg = new TLegend(.5,.7,.99,.99,"");
  leg->SetTextSize(0.03);
  leg->SetFillColor(0);
  leg->SetLineColor(0);
  //  TString varcut = variable;
  // varcut+=theHT;





  //  double etalow = theHT;
  //  double etahigh = theHT+thestep;

  TH1D *sdata=hSelection->Clone(); sdata->SetMarkerStyle(20);
   TString headerName="H_{T} >"; headerName+=theHT;
   TString varcut = variable; varcut+=theHT;
  //  TString headerNamea =""; headerNamea +=etalow;
  ///  TString headerNameb = " < |#eta_{j1}| < "; headerNameb+=etahigh;

   // leg->SetHeader(headerNamea+headerNameb);
   leg->SetHeader(headerName);
  leg->AddEntry(sdata,"data","LP");

  //  leg->AddEntry(hSelection,"Fit result","L");

  leg->AddEntry(hControl,"monte-Carlo (data-like)","L");
  //leg->AddEntry(hConversions,"Conversions from anti-selected events","L");

  hSelection->SetLineColor(kBlue); hSelection->SetLineWidth(3);
  hControl->SetLineColor(kBlue); hControl->SetLineStyle(1);hControl->SetLineWidth(3);
   hConversions->SetLineColor(kRed); hConversions->SetLineStyle(2);hConversions->SetLineWidth(3);
  
  //  gPad->SetLogy();

    RooPlot * xframe = x.frame();
 
    data.plotOn(xframe);//,Binning(100));
  //  data.statOn(xframe,Label(labelName),What("N"),CutRange("selection"),
  //	      Format("NEU",AutoPrecision(2)));
    
   model.plotOn(xframe);//,Binning(100));// model.paramOn(xframe,Label("Fit result"));

  // model.plotOn(xframe,Components(tConv),LineColor(kRed),LineStyle(kDashed));
  //model.plotOn(xframe,Components(tFakes),LineColor(kGreen),LineStyle(kDashed));

    data.plotOn(xframe);
   xframe->GetXaxis()->SetRangeUser(0.2,0.9);
   // xframe->GetYaxis()->SetRangeUser(0,2);
   xframe->Draw();
  // hControl->SetLineStyle();
  //
   //  xframe->SetTitle("selected events");
   xframe->SetTitle("anti-selected events");
//hSelection->Draw("E");
  //hSelection->SetTitle();
  //hControl->Draw("HISTSAME");
  leg->Draw("SAME");
    //    return;
  c->Update();
  c->SaveAs("Plots/"+file+"_RaT_"+varcut+".png");
	    //+file+"_RaT_"+variable+"_"+theHT+".png");
  return fit;
}
//// runCode // 0=merged, 1=1stRun, 2=2ndRun
void draw_1D_RFB_ETHF_tworange(char* dirName = "6rap3pt", int runCode=0,  bool isPrompt=false)
{
    gROOT->Macro("./tdrstyle_kyo.C");
    gStyle->SetTitleSize(0.046, "XYZ");
    gStyle->SetEndErrorSize(0);
    gStyle->SetOptTitle(0);
    gStyle->SetPadTopMargin(0.075);
    gStyle->SetPadBottomMargin(0.13); //KYO
    gStyle->SetPadLeftMargin(0.13); //KYO
    gStyle->SetPadRightMargin(0.075);
    gStyle->SetTitleXOffset(1.15);
    gStyle->SetTitleYOffset(1.22);

    writeExtraText = true;
    extraText  = "Preliminary";
    lumi_502TeV  = "34.6 nb^{-1}";
    int iPeriod = 0;
    int iPos=0;

    //double pxshift = 0.5;
    double pxshift = 1.;

    // set info.
    const Double_t br = 0.0593 ;
    const Double_t brErr = 0.0006;
    Double_t lumi_nb;
    Double_t lumi_nb_err;
    Double_t lumi_mub;
    Double_t lumi_mub_err;
    string runstring;
    string lumistring;
    string cmsstring = "CMS preliminary";
    string beamstring = "pPb #sqrt{s_{NN}} = 5.02 TeV";
    if (runCode ==0) {
        runstring = "All";
        lumi_nb =34.622;
        lumi_nb_err=1.2;
    }
    else if (runCode == 1) {
        runstring = "Pbp";    //1stRun
        lumi_nb =20.7;
        lumi_nb_err=0.7;
    }
    else if (runCode == 2) {
        runstring = "pPb";    //2ndRun
        lumi_nb = 14.0;
        lumi_nb_err=0.5;
    }
    else {
        cout << " *** Error!!! choose runCode 0, 1, or 2 " << endl;
        return ;
    }
    lumistring = Form("L_{int} = %.1f nb^{  -1}", lumi_nb);
    lumi_mub = lumi_nb * 1000; // (nb)^{-1} -> {#mub}^{-1}
    lumi_mub_err = lumi_nb_err * 1000; // (nb)^{-1} -> {#mub}^{-1}

    /////////////////////////////////////////////////////////////////////////
    // bin center & systematic uncertainties by hand
    //inh=0 : pT 5-6.5, rap 1.5-1.93
    //inh=1 : pT 6.5-30, rap 1.5-1.93
    //inh=2 : pT 6.5-30, rap 0.9-1.5
    //inh=3 : pT 6.5-30, rap 0.0-0.9
    const int nRap = 6;
    const int nRapTmp = nRap+1;
    const int nPt = 3;
    const int nPtTmp = nPt+1;
    const int nEt = 3;
    const int nEtTmp = nEt+1;
    const int nHist = 4;
    const int nHistTmp = nHist+1;
    Double_t pxtmp[nHist][nEt]; //x point to fill temp
    Double_t pytmp[nHist][nEt]; //y point to fill temp
    Double_t eytmp[nHist][nEt]; //y stat error to fill temp
    Double_t px[nEt] = {9.4, 24.3, 37.2}; // x point
    Double_t ex[nEt] = {0.,0.,0.}; // x stat error
    Double_t exsys[nEt] = {0.5, 0.5, 0.5};; //x sys error
    Double_t eysys[nHist][nEt]; //absolute y sys error
    Double_t eysysrel[nHist][nEt]; //relative y sys error
    Double_t eysysrelPR[nHist][nEt] = {
        {0.05299,0.06155,0.06715}, //1.5-1.93 low
        {0.05088,0.05442,0.05913}, //1.5-1.93
        {0.03741,0.04958,0.04227}, //0.9-1.5
        {0.04425,0.04528,0.05314} //0.0-0.9
    };
    Double_t eysysrelNP[nHist][nEt] = {
        {0.04971,0.06138,0.06459}, // 1.5-1.93 low
        {0.05188,0.05442,0.05999}, //0.5-1.93
        {0.03694,0.04952,0.04221}, //0.9-1.5
        {0.04242,0.04349,0.05162} //0.0-0.9
    };

    for (int inh = 0; inh < nHist; inh++ ) {
        for (int iet = 0; iet < nEt; iet++ ) {
            if (isPrompt) eysysrel[inh][iet] = eysysrelPR[inh][iet];
            else eysysrel[inh][iet] = eysysrelNP[inh][iet];
        }
    }

    //rap array in yCM (from forward to backward)
    Double_t rapArrNumFB[nRapTmp] = {1.93, 1.5, 0.9, 0., -0.9, -1.5, -1.93};// for pt dist.
    //Double_t rapArrNumBF[nRapTmp] = {-1.93, -1.5, -0.9, 0., 0.9, 1.5, 1.93};// for rap dist.
    Double_t rapBinW[nRap];
    for (Int_t iy=0; iy<nRap; iy++) {
        rapBinW[iy] = rapArrNumFB[iy]-rapArrNumFB[iy+1];
        cout << iy <<"th rapBinW = " << rapBinW[iy] <<endl;
    }
    //pt array
    Double_t ptArrNum[nPtTmp] = {5.0, 6.5, 10., 30.}; //6rap3pt
    Double_t ptBinW[nPt];
    for (Int_t ipt=0; ipt<nPt; ipt++) {
        ptBinW[ipt] = ptArrNum[ipt+1]-ptArrNum[ipt];
        cout << ipt <<"th ptBinW = " << ptBinW[ipt] <<endl;
    }
    //ethf array
    Double_t etArrNum[nEtTmp] = {0.0, 20.0, 30.0, 120.0};

    // array string
    string rapArr[nRap];
    for (Int_t iy=0; iy<nRap; iy++) {
        formRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapArr[iy]);
        cout << iy <<"th rapArr = " << rapArr[iy] << endl;
    }
    string ptArr[nPt];
    for (Int_t ipt=0; ipt<nPt; ipt++) {
        formPtArr(ptArrNum[ipt], ptArrNum[ipt+1], &ptArr[ipt]);
        cout << ipt <<"th ptArr = " << ptArr[ipt] << endl;
    }
    string etArr[nEt];
    for (Int_t i=0; i<nEt; i++) {
        formEtArr(etArrNum[i], etArrNum[i+1], &etArr[i]);
        cout << "etArr["<<i<<"] = "<< etArr[i].c_str() << endl;
    }

    // --- read-in file
    TFile * f2D = new TFile(Form("../fittingResult/total2Dhist_%s.root",dirName));
    cout << "dirName = " << dirName << endl;
    cout << "runCode = " << runCode << ", runstring = " << runstring.c_str() << endl;

    // --- read-in 2D hist for corrected yield
    TH2D* h2D_corrY_Pbp[nEt];
    TH2D* h2D_corrY_pPb[nEt];
    for (int iet=0; iet<nEt; iet++) {
        if (isPrompt) {
            h2D_corrY_Pbp[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_PR_Pbp_%d",iet));
            h2D_corrY_pPb[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_PR_pPb_%d",iet));
        }
        else {
            h2D_corrY_Pbp[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_NP_Pbp_%d",iet));
            h2D_corrY_pPb[iet] = (TH2D*)f2D->Get(Form("h2D_corrY_NP_pPb_%d",iet));
        }
        cout << iet << "th h2D_corrY_Pbp = " << h2D_corrY_Pbp[iet] << endl;
        cout << iet << "th h2D_corrY_pPb = " << h2D_corrY_pPb[iet] << endl;
    }

    const int nbinsX = h2D_corrY_Pbp[0]->GetNbinsX();
    const int nbinsY = h2D_corrY_Pbp[0]->GetNbinsY();
    cout << "nbinsX = " << nbinsX << endl;
    cout << "nbinsY = " << nbinsY << endl;
    if (nbinsX != nRap) {
        cout << " *** Error!!! nbinsX != nRap";
        return;
    };
    if (nbinsY != nPt) {
        cout << " *** Error!!! nbinsY != nPt";
        return;
    };

    // ---  projection to 1D hist
    TH1D* h1D_corrY_Pbp[nEt][nbinsX];
    TH1D* h1D_corrY_pPb[nEt][nbinsX];
    // iy=0 refers to forwards !!! (ordering here)
    for (Int_t iet=0; iet<nEt; iet++) {
        for (Int_t iy = 0; iy < nbinsX; iy++) {
            h1D_corrY_Pbp[iet][iy] = h2D_corrY_Pbp[iet]->ProjectionY(Form("h1D_corrY_Pbp_%d_%d",iet,iy),iy+1,iy+1);
            h1D_corrY_Pbp[iet][iy]->SetName(Form("h1D_corrY_Pbp_%d_%d",iet,iy));
            //for 2nd run
            h1D_corrY_pPb[iet][iy] = h2D_corrY_pPb[iet]->ProjectionY(Form("h1D_corrY_pPb_%d_%d",iet,iy),nbinsX-iy,nbinsX-iy);
            h1D_corrY_pPb[iet][iy]->SetName(Form("h1D_corrY_pPb_%d_%d",iet,iy));
        }
    }

    //////////////////////////////////////////////////////////////////////////////////////
    // 1) merge Pbp+pPb corrected yield
    TH1D* h1D_corrY_tot[nEt][nbinsX];
    for (Int_t iet=0; iet<nEt; iet++) {
        for (Int_t iy = 0; iy < nbinsX; iy++) {
            if (runCode ==0) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_Pbp[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
                h1D_corrY_tot[iet][iy]->Add(h1D_corrY_pPb[iet][iy]);
            }
            else if (runCode ==1) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_Pbp[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
            }
            else if (runCode ==2) {
                h1D_corrY_tot[iet][iy] = (TH1D*)h1D_corrY_pPb[iet][iy]->Clone(Form("h1D_corrY_tot_%d_%d",iet,iy));
            }
        }
    }

    //////////////////////////////////////////////////////////////////
    /////////// calculate RFB

    const int nRapRFB = 3;
    TH1D* h1D_RFB_tmp[nEt][nbinsX]; // corrYield with merged pT
    TH1D* h1D_RFB[nEt][nRapRFB]; // actual RFB vs pt

    // bin settingg
    string rapAbsArr[nRap];
    for (Int_t iy=0; iy<nRapRFB; iy++) {
        formAbsRapArr(rapArrNumFB[iy+1], rapArrNumFB[iy], &rapAbsArr[iy]);
        cout << iy <<"th rapAbsArr = " << rapAbsArr[iy] << endl;
    }
    Double_t ptArrRFBNum[] = {5.0, 6.5, 30.};
    const Int_t nPtRFB = sizeof(ptArrRFBNum)/sizeof(Double_t)-1;
    cout << "nPtRFB = " << nPtRFB << endl;

    // merging pT bins (KYO - byHand)
    double tmpPRval01, tmpPRerr01, tmpPRval02, tmpPRerr02;
    double actPRval01, actPRerr01, actPRval02, actPRerr02;
    for (int iet=0; iet<nEt; iet++) {
        for (int iy=0; iy<nRapRFB*2; iy++) {
            h1D_RFB_tmp[iet][iy]= new TH1D(Form("h1D_RFB_tmp_%d_%d",iet,iy),Form("h1D_RFB_tmp_%d_%d",iet,iy),nPtRFB,ptArrRFBNum);
            h1D_RFB_tmp[iet][iy]->Sumw2();
            actPRval01=0;
            actPRval02=0;
            actPRerr01=0;
            actPRerr02=0;
            // 1) pT 5-6.5 GeV
            tmpPRval01=0;
            tmpPRval02=0;
            tmpPRerr01=0;
            tmpPRerr02=0;
            if (iy==0 || iy==nRapRFB*2-1) {
                actPRval01=h1D_corrY_tot[iet][iy]->GetBinContent(1);
                actPRerr01=h1D_corrY_tot[iet][iy]->GetBinError(1);
                h1D_RFB_tmp[iet][iy]->SetBinContent(1,actPRval01);
                h1D_RFB_tmp[iet][iy]->SetBinError(1,actPRerr01);
            } else {
                h1D_RFB_tmp[iet][iy]->SetBinContent(1,0.);
                h1D_RFB_tmp[iet][iy]->SetBinError(1,0.);
            }
            // 2) pT 6.5-30. GeV
            tmpPRval01=0;
            tmpPRval02=0;
            tmpPRerr01=0;
            tmpPRerr02=0;
            tmpPRval01=h1D_corrY_tot[iet][iy]->GetBinContent(2);
            tmpPRerr01=h1D_corrY_tot[iet][iy]->GetBinError(2);
            tmpPRval02=h1D_corrY_tot[iet][iy]->GetBinContent(3);
            tmpPRerr02=h1D_corrY_tot[iet][iy]->GetBinError(3);
            actPRval02=tmpPRval01+tmpPRval02;
            actPRerr02=TMath::Sqrt( TMath::Power(tmpPRerr01,2) + TMath::Power(tmpPRerr02,2) );
            h1D_RFB_tmp[iet][iy]->SetBinContent(2,actPRval02);
            h1D_RFB_tmp[iet][iy]->SetBinError(2,actPRerr02);
        }
    }

    // actual RFB calculation	vs pT!!
    for (int iet=0; iet<nEt; iet++) {
        for (int iy=0; iy<nRapRFB; iy++) {
            h1D_RFB[iet][iy] = (TH1D*)h1D_RFB_tmp[iet][iy]->Clone(Form("h1D_RFB_%d_%d",iet,iy));
            h1D_RFB[iet][iy]->Divide(h1D_RFB_tmp[iet][2*nRapRFB-iy-1]);
            cout << iet<<"th, "<<iy<<"th h1D_RFB = "<<h1D_RFB[iet][iy]<<endl;
        }
    }

    ///////////////////////////////////////////////
    //////// --- RFB vs ETHF : 4 histograms
    //inh=0 : pT 5-6.5, rap 1.5-1.93
    //inh=1 : pT 6.5-30, rap 1.5-1.93
    //inh=2 : pT 6.5-30, rap 0.9-1.5
    //inh=3 : pT 6.5-30, rap 0.0-0.9
    double tmpRFBval01, tmpRFBerr01, tmpRFBval02, tmpRFBerr02, tmpRFBval03, tmpRFBerr03;
    TH1D* h1D_RFB_ETHF[nHist];

    for (int inh=0; inh< nHist; inh++) {
        h1D_RFB_ETHF[inh]= new TH1D(Form("h1D_RFB_ETHF_%d",inh),Form("h1D_RFB_ETHF_%d",inh),nEt,etArrNum);
        h1D_RFB_ETHF[inh]->Sumw2();
        tmpRFBval01=0;
        tmpRFBerr01=0;
        tmpRFBval02=0;
        tmpRFBerr02=0;
        tmpRFBval03=0;
        tmpRFBerr03=0;
        for (int iet=0; iet<nEt; iet++) {
            if (inh==0) {
                tmpRFBval01=h1D_RFB[iet][0]->GetBinContent(1);
                tmpRFBerr01=h1D_RFB[iet][0]->GetBinError(1);
                h1D_RFB_ETHF[inh]->SetBinContent(iet+1,tmpRFBval01);
                h1D_RFB_ETHF[inh]->SetBinError(iet+1,tmpRFBerr01);
            }
            else {
                tmpRFBval01=h1D_RFB[iet][inh-1]->GetBinContent(2);
                tmpRFBerr01=h1D_RFB[iet][inh-1]->GetBinError(2);
                h1D_RFB_ETHF[inh]->SetBinContent(iet+1,tmpRFBval01);
                h1D_RFB_ETHF[inh]->SetBinError(iet+1,tmpRFBerr01);
            }
        }
    }

    //////////////////////////////////////////////////////////////////
    /////////// samey
    //////////////////////////////////////////////////////////////////
    TCanvas* c1 = new TCanvas("c1","c1",600,600);
    c1->cd();

//	TLegend *legBL = new TLegend(0.16, 0.16, 0.43, 0.41); //bottom left
    TLegend *legBL = new TLegend(0.16, 0.16, 0.40, 0.36); //bottom left
    TLegend *legBL2 = new TLegend(0.16, 0.16, 0.40, 0.40); //bottom left
//	TLegend *legUR = new TLegend(0.36, 0.77, 0.89, 0.95); //upper left
    TLegend *legUR = new TLegend(0.34, 0.71, 0.89, 0.88); //upper left
    SetLegendStyle(legBL);
    SetLegendStyle(legBL2);
    //legBL->SetTextSize(0.032);
    legBL->SetTextSize(0.037);
    legBL2->SetTextSize(0.037);

    //globtex box for beam, rapidity, pT info
    TLatex* globtex = new TLatex();
    globtex->SetNDC();
    //globtex->SetTextAlign(12); //1:left, 2:vertical center
    globtex->SetTextAlign(32); //3:right 2:vertical center
    globtex->SetTextFont(42);
    globtex->SetTextSize(0.04);

    // convert to TGraphAsymErrors
    //RFB
    TGraphAsymmErrors*gRFB[nHist];
    for (int inh=0; inh< nHist; inh++) {
        gRFB[inh] = new TGraphAsymmErrors(h1D_RFB_ETHF[inh]);
        gRFB[inh]->SetName(Form("gRFB_%d",inh));
        for (int iet=0; iet<nEt; iet++) {
            gRFB[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            eytmp[inh][iet] = gRFB[inh] -> GetErrorY(iet);
//			gRFB[inh]->SetPoint(iet, px[iet], pytmp[inh][iet]);
            gRFB[inh]->SetPoint(iet, px[iet]+pxshift*inh, pytmp[inh][iet]);
            gRFB[inh]->SetPointEXlow(iet, ex[inh]);
            gRFB[inh]->SetPointEXhigh(iet, ex[inh]);
        }
    }

    //sys
    TGraphAsymmErrors* gRFB_sys[nHist];
    for (int inh=0; inh< nHist; inh++) {
        gRFB_sys[inh] = new TGraphAsymmErrors(h1D_RFB_ETHF[inh]);
        gRFB_sys[inh]->SetName(Form("gRFB_sys_%d",inh));
        for (int iet=0; iet<nEt; iet++) {
            gRFB_sys[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            //abs err calcul.
            eysys[inh][iet] = eysysrel[inh][iet]*pytmp[inh][iet];
            //gRFB_sys[inh]->SetPoint(iet, px[iet], pytmp[inh][iet]);
            gRFB_sys[inh]->SetPoint(iet, px[iet]+pxshift*inh, pytmp[inh][iet]);
            gRFB_sys[inh]->SetPointError(iet, exsys[iet], exsys[iet], eysys[inh][iet], eysys[inh][iet]);
            cout << "" << endl;
            cout << "pytmp["<<inh<<"]["<<iet<<"] = " << pytmp[inh][iet]<<endl;
            cout << "eytmp["<<inh<<"]["<<iet<<"] = " << eytmp[inh][iet]<<endl;
            cout << "eysys["<<inh<<"]["<<iet<<"] = " << eysys[inh][iet]<<endl;
        }
    }

    gRFB_sys[0]->GetXaxis()->SetTitle("E_{T}^{HF |#eta|>4} [GeV]");
    gRFB_sys[0]->GetXaxis()->CenterTitle();
    gRFB_sys[0]->GetYaxis()->SetTitle("R_{FB}");
    gRFB_sys[0]->GetXaxis()->SetLimits(0.,50.0);
    gRFB_sys[0]->SetMinimum(0.5);
    gRFB_sys[0]->SetMaximum(1.15);
    gRFB_sys[0]->SetFillColor(kViolet-9);
    gRFB_sys[0]->Draw("A2");
    gRFB_sys[1]->SetFillColor(kTeal-9);
    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->SetFillColor(kRed-9);
//	gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->SetFillColor(kAzure-9);
//	gRFB_sys[3]->Draw("2");

    SetGraphStyle(gRFB[0], 8, 2); //1.5-1.93 low
    SetGraphStyle(gRFB[1], 0, 5); //1.5-1.93
    SetGraphStyle(gRFB[2], 1, 3); //0.9-1.5
    SetGraphStyle(gRFB[3], 2, 0); //0-0.9
    gRFB[0]->SetMarkerSize(1.6);
    gRFB[0]->Draw("P");
    gRFB[1]->SetMarkerSize(2.1);
    gRFB[1]->Draw("P");

    dashedLine(0.,1.,50.,1.,1,1);
    legBL -> SetHeader ("1.5 < |y_{CM}| < 1.93");
    legBL -> AddEntry(gRFB[0],"5 < p_{T} < 6.5 GeV/c","lp");
    legBL -> AddEntry(gRFB[1],"6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[0],"1.5 < |y_{CM}| < 1.93,   5 < p_{T} < 6.5 GeV/c","lp");
//	legBL -> AddEntry(gRFB[1],"1.5 < |y_{CM}| < 1.93,  6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[2],"0.9 < |y_{CM}| < 1.5,   6.5 < p_{T} < 30 GeV/c","lp");
//	legBL -> AddEntry(gRFB[3],"0.0 < |y_{CM}| < 0.9,   6.5 < p_{T} < 30 GeV/c","lp");
    legBL->Draw();
    globtex->SetTextSize(0.045);
    globtex->SetTextFont(62);
    if (isPrompt) globtex->DrawLatex(0.88, 0.86, "Prompt J/#psi");
    else globtex->DrawLatex(0.88, 0.86, "Non-prompt J/#psi");

    CMS_lumi( c1, iPeriod, iPos );
    c1->Update();
    c1->SaveAs(Form("RFB_%s/RFB_ETHF_samey_isPrompt%d_%s.pdf",dirName,(int)isPrompt,runstring.c_str()));
    c1->SaveAs(Form("RFB_%s/RFB_ETHF_samey_isPrompt%d_%s.png",dirName,(int)isPrompt,runstring.c_str()));
    legBL->Clear();


    //////////////////////////////////////////////////////////////////
    /////////// samept
    //////////////////////////////////////////////////////////////////
    TCanvas* c2 = new TCanvas("c2","c2",600,600);
    c2->cd();

    for (int inh=1; inh< nHist; inh++) {
        for (int iet=0; iet<nEt; iet++) {
            gRFB[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            eytmp[inh][iet] = gRFB[inh] -> GetErrorY(iet);
            gRFB[inh]->SetPoint(iet, px[iet]+pxshift*(nHist-1-inh), pytmp[inh][iet]);
            //sys
            gRFB_sys[inh]->GetPoint(iet, pxtmp[inh][iet], pytmp[inh][iet]);
            gRFB_sys[inh]->SetPoint(iet, px[iet]+pxshift*(nHist-1-inh), pytmp[inh][iet]);
        }
    }

    gRFB_sys[0]->GetXaxis()->SetTitle("E_{T}^{HF |#eta|>4} [GeV]");
    gRFB_sys[0]->GetXaxis()->CenterTitle();
    gRFB_sys[0]->GetYaxis()->SetTitle("R_{FB}");
    gRFB_sys[0]->GetXaxis()->SetLimits(0.,50.0);
    gRFB_sys[0]->SetMinimum(0.5);
    gRFB_sys[0]->SetMaximum(1.15);
    gRFB_sys[0]->SetFillColor(kViolet-9);
    gRFB_sys[0]->Draw("A2");
    gRFB_sys[1]->SetFillColor(kTeal-9);
    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->SetFillColor(kRed-9);
//	gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->SetFillColor(kAzure-9);
//	gRFB_sys[3]->Draw("2");

    SetGraphStyle(gRFB[0], 8, 2); //1.5-1.93 low
    SetGraphStyle(gRFB[1], 0, 5); //1.5-1.93
    SetGraphStyle(gRFB[2], 1, 3); //0.9-1.5
    SetGraphStyle(gRFB[3], 2, 0); //0-0.9
    gRFB[0]->SetMarkerSize(1.6);
    gRFB[0]->Draw("P");
    gRFB[1]->SetMarkerSize(2.1);
    gRFB[1]->Draw("P");








    // just for drawing
    gRFB_sys[0]->SetFillColor(kWhite);
    gRFB_sys[0]->Draw("A2");

    gRFB_sys[1]->Draw("2");
    gRFB_sys[2]->Draw("2");
    gRFB_sys[3]->Draw("2");

    gRFB[1]->Draw("P");
    gRFB[2]->Draw("P");
    gRFB[3]->Draw("P");

    dashedLine(0.,1.,50.,1.,1,1);
    legBL2 -> SetHeader ("6.5 < p_{T} < 30 GeV/c");
    legBL2 -> AddEntry(gRFB[3],"0.0 < |y_{CM}| < 0.9","lp");
    legBL2 -> AddEntry(gRFB[2],"0.9 < |y_{CM}| < 1.5","lp");
    legBL2 -> AddEntry(gRFB[1],"1.5 < |y_{CM}| < 1.93","lp");
    legBL2 ->Draw();
    globtex->SetTextSize(0.045);
    globtex->SetTextFont(62);
    if (isPrompt) globtex->DrawLatex(0.88, 0.86, "Prompt J/#psi");
    else globtex->DrawLatex(0.88, 0.86, "Non-prompt J/#psi");

    CMS_lumi( c2, iPeriod, iPos );
    c2->Update();
    c2->SaveAs(Form("RFB_%s/RFB_ETHF_samept_isPrompt%d_%s.pdf",dirName,(int)isPrompt,runstring.c_str()));
    c2->SaveAs(Form("RFB_%s/RFB_ETHF_samept_isPrompt%d_%s.png",dirName,(int)isPrompt,runstring.c_str()));

#if 0
    ///////////////////////////////////////////////////////////////////
    // save as a root file
    TFile *outFile = new TFile(Form("RFB_%s/RFB_ETHF_FWonly_isPrompt%d.root",dirName,(int)isPrompt),"RECREATE");
    outFile->cd();
    for (int inh=0; inh< nHist; inh++) {
        gRFB_sys[inh]->Write();
        gRFB[inh]->Write();
    }
    outFile->Close();
#endif

    return;

} // end of main func.
void makeHTPlots_Control() {

  //  fit_info* fb = draw_tree(0.1);
  //  return;
  gSystem->Load("libRooFit"); using namespace RooFit;
 
  TGraphErrors* g1=new TGraphErrors(100);
  g1->SetMarkerColor(kRed);g1->SetLineColor(kRed);
  g1->SetMarkerStyle(29); g1->SetMarkerSize(2.5);
  g1->SetLineWidth(3);
  TGraphErrors* g2=new TGraphErrors(100);
  g2->SetMarkerStyle(29); g2->SetMarkerSize(2.5);
  g2->SetMarkerColor(14);g2->SetLineColor(14);
  g2->SetLineWidth(3);
  TGraphErrors* g3=new TGraphErrors(100);
  g3->SetMarkerStyle(20); g3->SetMarkerSize(1.5);
  g3->SetLineWidth(2.5);

  TGraphErrors* fg1=new TGraphErrors(100);
  fg1->SetMarkerColor(kRed);fg1->SetLineColor(kRed);
  fg1->SetMarkerStyle(29); fg1->SetMarkerSize(2.5);
  fg1->SetLineWidth(3);
  TGraphErrors* fg2=new TGraphErrors(100);
  fg2->SetMarkerStyle(29); fg2->SetMarkerSize(2.5);
  fg2->SetMarkerColor(14);fg2->SetLineColor(14);
  fg2->SetLineWidth(3);


  int region=1;
  bool addW=false;

  int i=0;
  double step=0.5;
  //  for (double nj=0.05; nj<0.9; nj+=0.1) { // Iso bins
   for (double nj=40.; nj<=150.; nj+=15.) { // HT bins
     //  for (double nj=0; nj<=3.5; nj+=step) { // j1 eta bins
    fit_info* fb = draw_tree(nj,step);

    //    double comb_error_sum_b = sqrt(fb->err1_corr*fb->err1_corr + fb->err2_corr*fb->err2_corr 
    //				     + 2.*fb->err1_corr*fb->err2_corr*fb->gcor12);

    cout << "ISo < " << nj << endl;

    //    cout << " a= " << (fb->corr1+fb->corr2) << endl;
    //    cout << " b= " << (fb->icorr1+fb->icorr2) << endl;

    //    double RaT= ((fb->corr1+fb->corr2) / (fb->icorr1+fb->icorr2));
    //    double eRaT=error((fb->corr1+fb->corr2),(fb->icorr1+fb->icorr2));

    double eNom=error((fb->nom),(fb->inom));
    double eCtrl=error((fb->ctrl),(fb->ictrl));

    //    cout << "RaT = " << RaT << " +/- " << eRaT << endl;

    //    g1->SetPoint(i,nj,RaT); g1->SetPointError(i,0.,eRaT);
    
    g1->SetPoint(i,nj,(fb->ctrl/fb->ictrl)); g1->SetPointError(i,0.1,eCtrl);
    g3->SetPoint(i,nj,(fb->nom/fb->inom)); g3->SetPointError(i,0.1,eNom);

    i++;
  }

  setTDRStyle();

  TCanvas* can=new TCanvas("itest","");

  gPad->SetGridx(); gPad->SetGridy();
  gPad->SetLogy();

  TLegend *leg = new TLegend(.4,.8.5,.99,.99,"");
  leg->SetTextSize(0.033);
    leg->SetHeader("ele ID inversion anti-selection region");
    //leg->SetHeader("selection region");
      //"Control region (ele ID anti-selection)
  leg->AddEntry(g3,"data","P");
  leg->AddEntry(g1,"monte carlo (data-like)","P");
//  leg->AddEntry(g2,"predicted (W+QCD)","P");

  leg->SetFillColor(0);
  leg->SetLineColor(0);

  //  g2->GetHistogram()->GetXaxis()->SetRangeUser(-0.5,3.5);
  //g2->Draw("AP");
  //g1->SetTitle(";|#eta_{j1}| bin;RaT = #frac{N(aT>0.55)}{N(aT>0)}");
 g1->SetTitle(";H_{T} cut [GeV];RaT = f(#alpha_{T}>0.55)");
  g1->Draw("AP");

  //  g1->Fit("pol1","R","",50.,100.);
  g3->Draw("P");
  g1->GetYaxis()->SetRangeUser(0.0007,2.);
  g1->GetYaxis()->SetTitleOffset(0.75);
  //  g1->GetXaxis()->SetRangeUser(20.,140.);
  leg->Draw("SAME");
  can->SaveAs("Plots/"+file+"RaT_vs_"+variable+".png");

}
示例#18
0
int main(){

	

		std::vector<double> RMSmeas;
		std::vector<double> RMSmin;
		//std::vector<double> RMSelim;
		std::vector<double> initP;
		std::vector<double> RMSmin2;

		//placeholder vectors for quick and easy parsing of txt file (this isnt that efficient)
		//the initP and meas values for the plot come from minimalist1 
		std::vector<double> RMSmeas2;
		std::vector<double>initP2;

		

		std::ifstream f1("RMSmin.txt");
		std::ifstream f2("RMSmin2.txt");

		
		double temp;
		while(f1>>temp){
			RMSmeas.push_back(temp);

			f1>>temp;
			RMSmin.push_back(temp);

			//f1>>temp;
			//RMSelim.push_back(temp);
	
			f1>>temp;

			initP.push_back(temp);

		}
		while(f2>>temp){
			RMSmeas2.push_back(temp);
			
			f2>>temp;
			RMSmin2.push_back(temp);
			f2>>temp;
			initP2.push_back(temp);
		}
		int n = RMSmeas.size();

		double measured[n], minimalist[n], elimination[n], inp[n], minimalist2[n], err_min[n], err_min2[n];

		//copy to double arrays because it would be too convenient to use vectors with root
		for(int i=0; i<n; i++){
			measured[i] = RMSmeas[i];
			minimalist[i] = RMSmin[i];
			//elimination[i] = RMSelim[i];
			minimalist2[i] = RMSmin2[i];
			inp[i] = initP[i];
			//err_min[i] = RMSmin[i]/
		}

		TCanvas *c1 = new TCanvas("c1","Epi RMS vs initial momentum",200,10,800,600);

		//TMultiGraph *mg = new TMultiGraph();

		TGraph *meas = new TGraph(n,inp,measured);
		TGraph *min = new TGraph(n,inp,minimalist);
		TGraph *min2 = new TGraph(n,inp,minimalist2);
		//TGraph *elim = new TGraph(n,inp,elimination);
		meas->SetName("meas");
		min->SetName("min");
		min2->SetName("min2");
		
		

		//measured rms options
		meas->SetTitle("E_{#pi^{0}} RMS vs |P_{#pi^{0}}|;Initial Momentum P_{#pi^{0}} GEV;RMS (GEV)"); 
		meas->SetMarkerStyle(21);
		meas->SetMarkerColor(2);
		meas->SetLineColor(4);
		meas->Draw("AP");

		//meas->GetXaxis()->SetTitle("GEV");
		//meas->GetYaxis()->SetTitle("RMS");
		
		min->SetMarkerColor(4);
		min->SetMarkerStyle(22);
		min->SetLineColor(3);
		min->Draw("P");

		//elim->SetMarkerColor(3);
		//elim->SetMarkerStyle(3);
		//elim->SetLineColor(2);
		//elim->Draw("CP");
		
		min2->SetMarkerColor(5);
		min2->SetMarkerStyle(20);
		min2->SetLineColor(5);
		min2->Draw("P");

		TLegend* legend = new TLegend(0.1,0.7,0.48,0.9);
		legend->AddEntry("meas", "Measured", "p");
		legend->AddEntry("min", "Minimalist", "p");
		legend->AddEntry("min2", "Minimalist2", "p");
		legend->Draw();

		//mg->Add(meas);
		//mg->Add(min);
		//mg->Add(elim);

		//mg->Draw("AC");

		c1->Print("E_PIrms_vs_intial_momentum.pdf");
		
	
}
示例#19
0
void 
HTT_MT_X(bool scaled=true, bool log=true, float min=0.1, float max=-1., const char* inputfile="root/$HISTFILE", const char* directory="muTau_$CATEGORY")
{
  // defining the common canvas, axes pad styles
  SetStyle(); gStyle->SetLineStyleString(11,"20 10");

  // determine category tag
  const char* category_extra = "";
  if(std::string(directory) == std::string("muTau_0jet_low"  )){ category_extra = "0 jet, low p_{T}";  }
  if(std::string(directory) == std::string("muTau_0jet_high" )){ category_extra = "0 jet, high p_{T}"; }
  if(std::string(directory) == std::string("muTau_boost_low" )){ category_extra = "1 jet, low p_{T}";  }
  if(std::string(directory) == std::string("muTau_boost_high")){ category_extra = "1 jet, high p_{T}"; }
  if(std::string(directory) == std::string("muTau_vbf"       )){ category_extra = "2 jet (VBF)";       }
  if(std::string(directory) == std::string("muTau_nobtag"    )){ category_extra = "No B-Tag";          }
  if(std::string(directory) == std::string("muTau_btag"      )){ category_extra = "B-Tag";             }

  const char* dataset;
  if(std::string(inputfile).find("7TeV")!=std::string::npos){dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 4.9 fb^{-1} at 7 TeV";}
  if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 19.4 fb^{-1} at 8 TeV";}
#ifdef MSSM
  if(std::string(inputfile).find("8TeV")!=std::string::npos){dataset = "CMS Preliminary,  H#rightarrow#tau#tau, 12.1 fb^{-1} at 8 TeV";}
#endif
 
  // open example histogram file
  TFile* input = new TFile(inputfile);
  TH1F* Fakes  = refill((TH1F*)input->Get(TString::Format("%s/QCD"   , directory)), "QCD"); InitHist(Fakes, "", "", kMagenta-10, 1001);
  TH1F* EWK1   = refill((TH1F*)input->Get(TString::Format("%s/W"     , directory)), "W"  ); InitHist(EWK1 , "", "", kRed    + 2, 1001);
#ifdef EXTRA_SAMPLES
  TH1F* EWK2   = refill((TH1F*)input->Get(TString::Format("%s/ZJ"    , directory)), "ZJ" ); InitHist(EWK2 , "", "", kRed    + 2, 1001);
  TH1F* EWK3   = refill((TH1F*)input->Get(TString::Format("%s/ZL"    , directory)), "ZL" ); InitHist(EWK3 , "", "", kRed    + 2, 1001);
#else
  TH1F* EWK2   = refill((TH1F*)input->Get(TString::Format("%s/ZLL"   , directory)), "ZLL"); InitHist(EWK2 , "", "", kRed    + 2, 1001);
#endif
  TH1F* EWK    = refill((TH1F*)input->Get(TString::Format("%s/VV"    , directory)), "VV" ); InitHist(EWK  , "", "", kRed    + 2, 1001);
  TH1F* ttbar  = refill((TH1F*)input->Get(TString::Format("%s/TT"    , directory)), "TT" ); InitHist(ttbar, "", "", kBlue   - 8, 1001);
  TH1F* Ztt    = refill((TH1F*)input->Get(TString::Format("%s/ZTT"   , directory)), "ZTT"); InitHist(Ztt  , "", "", kOrange - 4, 1001);
#ifdef MSSM
  float ggHScale = 1., bbHScale = 1.;
  ggHScale = ($MSSM_SIGNAL_ggH_xseff_A + $MSSM_SIGNAL_ggH_xseff_hH);
  bbHScale = ($MSSM_SIGNAL_bbH_xseff_A + $MSSM_SIGNAL_bbH_xseff_hH);
 //  float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=20, A + H for the time being
//   if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = ( 9157.9*0.119 + 10180.7*0.120)/1000.;
//                                                              bbHScale = (23314.3*0.119 + 21999.3*0.120)/1000.; }
//   if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (11815.3*0.119 + 13124.9*0.120)/1000.;
//                                                              bbHScale = (31087.9*0.119 + 29317.8*0.120)/1000.; }
 //  float ggHScale = 1., bbHScale = 1.; // scenario for MSSM, mhmax, mA=160, tanb=10, A + H for the time being
//   if(std::string(inputfile).find("7TeV")!=std::string::npos){ ggHScale = (2111.4*0.11 + 4022.9*0.11)/1000.;
//                                                               bbHScale = (6211.6*0.11 + 5147.0*0.11)/1000.; }
//   if(std::string(inputfile).find("8TeV")!=std::string::npos){ ggHScale = (2729.9*0.11 + 5193.2*0.11)/1000.;
//                                                               bbHScale = (8282.7*0.11 + 6867.8*0.11)/1000.; }
  TH1F* ggH    = refill((TH1F*)input->Get(TString::Format("%s/ggH160", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(ggHScale);
  TH1F* bbH    = refill((TH1F*)input->Get(TString::Format("%s/bbH160", directory)), "bbH"); InitSignal(bbH); bbH ->Scale(bbHScale);
#else
#ifndef DROP_SIGNAL
  TH1F* ggH    = refill((TH1F*)input->Get(TString::Format("%s/ggH125", directory)), "ggH"); InitSignal(ggH); ggH ->Scale(SIGNAL_SCALE);
  TH1F* qqH    = refill((TH1F*)input->Get(TString::Format("%s/qqH125", directory)), "qqH"); InitSignal(qqH); qqH ->Scale(SIGNAL_SCALE);
  TH1F* VH     = refill((TH1F*)input->Get(TString::Format("%s/VH125" , directory)), "VH" ); InitSignal(VH ); VH  ->Scale(SIGNAL_SCALE);
#endif
#endif
  TH1F* data   = refill((TH1F*)input->Get(TString::Format("%s/data_obs", directory)), "data", true);
  InitHist(data, "#bf{m_{#tau#tau} [GeV]}", "#bf{dN/dm_{#tau#tau} [1/GeV]}"); InitData(data);

  TH1F* ref=(TH1F*)Fakes->Clone("ref");
  ref->Add(EWK1 );
  ref->Add(EWK2 );
#ifdef EXTRA_SAMPLES
  ref->Add(EWK3 );
#endif
  ref->Add(EWK  );
  ref->Add(ttbar);
  ref->Add(Ztt  );

  double unscaled[7];
  unscaled[0] = Fakes->Integral();
  unscaled[1] = EWK  ->Integral();
  unscaled[1]+= EWK1 ->Integral();
  unscaled[1]+= EWK2 ->Integral();
#ifdef EXTRA_SAMPLES
  unscaled[1]+= EWK3 ->Integral();
#endif
  unscaled[2] = ttbar->Integral();
  unscaled[3] = Ztt  ->Integral();
#ifdef MSSM
  unscaled[4] = ggH  ->Integral();
  unscaled[5] = bbH  ->Integral();
  unscaled[6] = 0;
#else
#ifndef DROP_SIGNAL
  unscaled[4] = ggH  ->Integral();
  unscaled[5] = qqH  ->Integral();
  unscaled[6] = VH   ->Integral();
#endif
#endif

  if(scaled){
    rescale(Fakes, 7); 
    rescale(EWK1 , 3); 
    rescale(EWK2 , 4); 
#ifdef EXTRA_SAMPLES
    rescale(EWK3 , 5);
#endif 
    rescale(EWK  , 6); 
    rescale(ttbar, 2); 
    rescale(Ztt  , 1);
#ifdef MSSM
    rescale(ggH  , 8); 
    rescale(bbH  , 9);  
#else
#ifndef DROP_SIGNAL
    rescale(ggH  , 8); 
    rescale(qqH  , 9);  
    rescale(VH   ,10);  
#endif
#endif
  }

  TH1F* scales[7];
  scales[0] = new TH1F("scales-Fakes", "", 7, 0, 7);
  scales[0]->SetBinContent(1, unscaled[0]>0 ? (Fakes->Integral()/unscaled[0]-1.) : 0.);
  scales[1] = new TH1F("scales-EWK"  , "", 7, 0, 7);
  scales[1]->SetBinContent(2, unscaled[1]>0 ? ((EWK  ->Integral()
					       +EWK1 ->Integral()
					       +EWK2 ->Integral()
#ifdef EXTRA_SAMPLES
					       +EWK3 ->Integral()
#endif
						)/unscaled[1]-1.) : 0.);
  scales[2] = new TH1F("scales-ttbar", "", 7, 0, 7);
  scales[2]->SetBinContent(3, unscaled[2]>0 ? (ttbar->Integral()/unscaled[2]-1.) : 0.);
  scales[3] = new TH1F("scales-Ztt"  , "", 7, 0, 7);
  scales[3]->SetBinContent(4, unscaled[3]>0 ? (Ztt  ->Integral()/unscaled[3]-1.) : 0.);
#ifdef MSSM
  scales[4] = new TH1F("scales-ggH"  , "", 7, 0, 7);
  scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH  ->Integral()/unscaled[4]-1.) : 0.);
  scales[5] = new TH1F("scales-bbH"  , "", 7, 0, 7);
  scales[5]->SetBinContent(6, unscaled[5]>0 ? (bbH  ->Integral()/unscaled[5]-1.) : 0.);
  scales[6] = new TH1F("scales-NONE" , "", 7, 0, 7);
  scales[6]->SetBinContent(7, 0.);
#else
#ifndef DROP_SIGNAL
  scales[4] = new TH1F("scales-ggH"  , "", 7, 0, 7);
  scales[4]->SetBinContent(5, unscaled[4]>0 ? (ggH  ->Integral()/unscaled[4]-1.) : 0.);
  scales[5] = new TH1F("scales-qqH"  , "", 7, 0, 7);
  scales[5]->SetBinContent(6, unscaled[5]>0 ? (qqH  ->Integral()/unscaled[5]-1.) : 0.);
  scales[6] = new TH1F("scales-VH"   , "", 7, 0, 7);
  scales[6]->SetBinContent(7, unscaled[6]>0 ? (VH   ->Integral()/unscaled[6]-1.) : 0.);
#endif
#endif

  EWK1 ->Add(Fakes);
  EWK2 ->Add(EWK1 );
#ifdef EXTRA_SAMPLES
  EWK3 ->Add(EWK2 );
  EWK  ->Add(EWK3 );
#else
  EWK  ->Add(EWK2 );
#endif
  ttbar->Add(EWK  );
  Ztt  ->Add(ttbar);
  if(log){
#ifdef MSSM
    ggH  ->Add(bbH);
#else
#ifndef DROP_SIGNAL
    qqH  ->Add(VH );
    ggH  ->Add(qqH);
#endif
#endif
  }
  else{
#ifdef MSSM    
    bbH  ->Add(Ztt);
    ggH  ->Add(bbH);
#else
#ifndef DROP_SIGNAL
    VH   ->Add(Ztt);
    qqH  ->Add(VH );
    ggH  ->Add(qqH);
#endif
#endif
  }

  /*
    Mass plot before and after fit
  */
  TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600);

  canv->cd();
  if(log){ canv->SetLogy(1); }
#if defined MSSM
  if(!log){ data->GetXaxis()->SetRange(0, data->FindBin(350)); } else{ data->GetXaxis()->SetRange(0, data->FindBin(1000)); };
#else
  data->GetXaxis()->SetRange(0, data->FindBin(350));
#endif
  data->SetNdivisions(505);
  data->SetMinimum(min);
  data->SetMaximum(max>0 ? max : std::max(maximum(data, log), maximum(Ztt, log)));
  data->Draw("e");

  TH1F* errorBand = (TH1F*)Ztt ->Clone();
  errorBand  ->SetMarkerSize(0);
  errorBand  ->SetFillColor(1);
  errorBand  ->SetFillStyle(3013);
  errorBand  ->SetLineWidth(1);
  for(int idx=0; idx<errorBand->GetNbinsX(); ++idx){
    if(errorBand->GetBinContent(idx)>0){
      std::cout << "Uncertainties on summed background samples: " << errorBand->GetBinError(idx)/errorBand->GetBinContent(idx) << std::endl;
      break;
    }
  }
  if(log){
    Ztt  ->Draw("histsame");
    ttbar->Draw("histsame");
    EWK  ->Draw("histsame");
    Fakes->Draw("histsame");
    $DRAW_ERROR
#ifndef DROP_SIGNAL
    ggH  ->Draw("histsame");
#endif
  }
  else{
#ifndef DROP_SIGNAL
    ggH  ->Draw("histsame");
#endif
    Ztt  ->Draw("histsame");
    ttbar->Draw("histsame");
    EWK  ->Draw("histsame");
    Fakes->Draw("histsame");
    $DRAW_ERROR
  }
  data->Draw("esame");
  canv->RedrawAxis();

  //CMSPrelim(dataset, "#tau_{#mu}#tau_{h}", 0.17, 0.835);
  CMSPrelim(dataset, "", 0.16, 0.835);  
  TPaveText* chan     = new TPaveText(0.20, 0.74+0.061, 0.32, 0.74+0.161, "NDC");
  chan->SetBorderSize(   0 );
  chan->SetFillStyle(    0 );
  chan->SetTextAlign(   12 );
  chan->SetTextSize ( 0.05 );
  chan->SetTextColor(    1 );
  chan->SetTextFont (   62 );
  chan->AddText("#mu#tau_{h}");
  chan->Draw();

  TPaveText* cat      = new TPaveText(0.20, 0.68+0.061, 0.32, 0.68+0.161, "NDC");
  cat->SetBorderSize(   0 );
  cat->SetFillStyle(    0 );
  cat->SetTextAlign(   12 );
  cat->SetTextSize ( 0.05 );
  cat->SetTextColor(    1 );
  cat->SetTextFont (   62 );
  cat->AddText(category_extra);
  cat->Draw();

#ifdef MSSM
  TPaveText* massA      = new TPaveText(0.75, 0.48+0.061, 0.85, 0.48+0.161, "NDC");
  massA->SetBorderSize(   0 );
  massA->SetFillStyle(    0 );
  massA->SetTextAlign(   12 );
  massA->SetTextSize ( 0.03 );
  massA->SetTextColor(    1 );
  massA->SetTextFont (   62 );
  massA->AddText("m_{A}=160GeV");
  massA->Draw();

  TPaveText* tanb      = new TPaveText(0.75, 0.44+0.061, 0.85, 0.44+0.161, "NDC");
  tanb->SetBorderSize(   0 );
  tanb->SetFillStyle(    0 );
  tanb->SetTextAlign(   12 );
  tanb->SetTextSize ( 0.03 );
  tanb->SetTextColor(    1 );
  tanb->SetTextFont (   62 );
  tanb->AddText("tan#beta=20");
  tanb->Draw();

  TPaveText* scen      = new TPaveText(0.75, 0.40+0.061, 0.85, 0.40+0.161, "NDC");
  scen->SetBorderSize(   0 );
  scen->SetFillStyle(    0 );
  scen->SetTextAlign(   12 );
  scen->SetTextSize ( 0.03 );
  scen->SetTextColor(    1 );
  scen->SetTextFont (   62 );
  scen->AddText("mhmax");
  scen->Draw();
#endif

#ifdef MSSM
  TLegend* leg = new TLegend(0.45, 0.65, 0.95, 0.90);
  SetLegendStyle(leg);
  leg->AddEntry(ggH  , "#phi#rightarrow#tau#tau" , "L" );
#else
  TLegend* leg = new TLegend(0.50, 0.65, 0.95, 0.90);
  SetLegendStyle(leg);
#ifndef DROP_SIGNAL
  if(SIGNAL_SCALE!=1){
    leg->AddEntry(ggH  , TString::Format("%.0f#timesH(125 GeV)#rightarrow#tau#tau", SIGNAL_SCALE) , "L" );
  }
  else{
    leg->AddEntry(ggH  , "H(125 GeV)#rightarrow#tau#tau" , "L" );
  }
#endif
#endif
  leg->AddEntry(data , "observed"                       , "LP");
  leg->AddEntry(Ztt  , "Z#rightarrow#tau#tau"           , "F" );
  leg->AddEntry(ttbar, "t#bar{t}"                       , "F" );
  leg->AddEntry(EWK  , "electroweak"                    , "F" );
  leg->AddEntry(Fakes, "QCD"                            , "F" );
  $ERROR_LEGEND
  leg->Draw();

//#ifdef MSSM
//  TPaveText* mssm  = new TPaveText(0.69, 0.85, 0.90, 0.90, "NDC");
//  mssm->SetBorderSize(   0 );
//  mssm->SetFillStyle(    0 );
//  mssm->SetTextAlign(   12 );
//  mssm->SetTextSize ( 0.03 );
//  mssm->SetTextColor(    1 );
//  mssm->SetTextFont (   62 );
//  mssm->AddText("(m_{A}=120, tan#beta=10)");
//  mssm->Draw();
//#else
//  TPaveText* mssm  = new TPaveText(0.83, 0.85, 0.95, 0.90, "NDC");
//  mssm->SetBorderSize(   0 );
//  mssm->SetFillStyle(    0 );
//  mssm->SetTextAlign(   12 );
//  mssm->SetTextSize ( 0.03 );
//  mssm->SetTextColor(    1 );
//  mssm->SetTextFont (   62 );
//  mssm->AddText("m_{H}=125");
//  mssm->Draw();
//#endif

  /*
    Ratio Data over MC
  */
  TCanvas *canv0 = MakeCanvas("canv0", "histograms", 600, 400);
  canv0->SetGridx();
  canv0->SetGridy();
  canv0->cd();

  TH1F* zero = (TH1F*)ref->Clone("zero"); zero->Clear();
  TH1F* rat1 = (TH1F*)data->Clone("rat"); 
  rat1->Divide(Ztt);
  for(int ibin=0; ibin<rat1->GetNbinsX(); ++ibin){
    if(rat1->GetBinContent(ibin+1)>0){
      // catch cases of 0 bins, which would lead to 0-alpha*0-1
      rat1->SetBinContent(ibin+1, rat1->GetBinContent(ibin+1)-1.);
    }
    zero->SetBinContent(ibin+1, 0.);
  }
  rat1->SetLineColor(kBlack);
  rat1->SetFillColor(kGray );
  rat1->SetMaximum(+0.5);
  rat1->SetMinimum(-0.5);
  rat1->GetYaxis()->CenterTitle();
  rat1->GetYaxis()->SetTitle("#bf{Data/MC-1}");
  rat1->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}");
  rat1->Draw();
  zero->SetLineColor(kBlack);
  zero->Draw("same");
  canv0->RedrawAxis();

  /*
    Ratio After fit over Prefit
  */
  TCanvas *canv1 = MakeCanvas("canv1", "histograms", 600, 400);
  canv1->SetGridx();
  canv1->SetGridy();
  canv1->cd();

  TH1F* rat2 = (TH1F*) Ztt->Clone("rat2");
  rat2->Divide(ref);
  for(int ibin=0; ibin<rat2->GetNbinsX(); ++ibin){
    if(rat2->GetBinContent(ibin+1)>0){
      // catch cases of 0 bins, which would lead to 0-alpha*0-1
      rat2 ->SetBinContent(ibin+1, rat2->GetBinContent(ibin+1)-1.);
    }
  }
  rat2->SetLineColor(kRed+ 3);
  rat2->SetFillColor(kRed-10);
  rat2->SetMaximum(+0.3);
  rat2->SetMinimum(-0.3);
  rat2->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}");
  rat2->GetYaxis()->CenterTitle();
  rat2->GetXaxis()->SetTitle("#bf{m_{#tau#tau} [GeV]}");
  rat2->Draw();
  zero->SetLineColor(kBlack);
  zero->Draw("same");
  canv1->RedrawAxis();

  /*
    Relative shift per sample
  */
  TCanvas *canv2 = MakeCanvas("canv2", "histograms", 600, 400);
  canv2->SetGridx();
  canv2->SetGridy();
  canv2->cd();

  InitHist  (scales[0], "", "", kMagenta-10, 1001);
  InitHist  (scales[1], "", "", kRed    + 2, 1001);
  InitHist  (scales[2], "", "", kBlue   - 8, 1001);
  InitHist  (scales[3], "", "", kOrange - 4, 1001);
#ifndef DROP_SIGNAL
  InitSignal(scales[4]);
  InitSignal(scales[5]);
  InitSignal(scales[6]);
#endif
  scales[0]->Draw();
  scales[0]->GetXaxis()->SetBinLabel(1, "#bf{Fakes}");
  scales[0]->GetXaxis()->SetBinLabel(2, "#bf{EWK}"  );
  scales[0]->GetXaxis()->SetBinLabel(3, "#bf{ttbar}");
  scales[0]->GetXaxis()->SetBinLabel(4, "#bf{Ztt}"  );
#ifdef MSSM
  scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}"  );
  scales[0]->GetXaxis()->SetBinLabel(6, "#bf{bbH}"  );
  scales[0]->GetXaxis()->SetBinLabel(7, "NONE"      );
#else
  scales[0]->GetXaxis()->SetBinLabel(5, "#bf{ggH}"  );
  scales[0]->GetXaxis()->SetBinLabel(6, "#bf{qqH}"  );
  scales[0]->GetXaxis()->SetBinLabel(7, "#bf{VH}"   );
#endif
  scales[0]->SetMaximum(+1.0);
  scales[0]->SetMinimum(-1.0);
  scales[0]->GetYaxis()->CenterTitle();
  scales[0]->GetYaxis()->SetTitle("#bf{Fit/Prefit-1}");
  scales[1]->Draw("same");
  scales[2]->Draw("same");
  scales[3]->Draw("same");
#ifndef DROP_SIGNAL
  scales[4]->Draw("same");
  scales[5]->Draw("same");
  scales[6]->Draw("same");
#endif
  zero->Draw("same");
  canv2->RedrawAxis();

  /*
    prepare output
  */
  bool isSevenTeV = std::string(inputfile).find("7TeV")!=std::string::npos;
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.png"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.pdf"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv ->Print(TString::Format("%s_%sscaled_%s_%s.eps"       , directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv0->Print(TString::Format("%s_datamc_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv1->Print(TString::Format("%s_prefit_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.png", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : "")); 
  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.pdf", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  canv2->Print(TString::Format("%s_sample_%sscaled_%s_%s.eps", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""));
  TFile* output = new TFile(TString::Format("%s_%sscaled_%s_%s.root", directory, scaled ? "re" : "un", isSevenTeV ? "7TeV" : "8TeV", log ? "LOG" : ""), "update");
  output->cd();
  data ->Write("data_obs");
  Fakes->Write("Fakes"   );
  EWK  ->Write("EWK"     );
  ttbar->Write("ttbar"   );
  Ztt  ->Write("Ztt"     );
#ifdef MSSM
  ggH  ->Write("ggH"     );
  bbH  ->Write("bbH"     );
#else
#ifndef DROP_SIGNAL
  ggH  ->Write("ggH"     );
  qqH  ->Write("qqH"     );
  VH   ->Write("VH"      );
#endif
#endif
  if(errorBand){
    errorBand->Write("errorBand");
  }
  output->Close();
}
示例#20
0
int main( int argc, char* argv[] ) {

  DrawTools::setStyle();
  
  
  std::string tag = "V00";
  std::string config = "SiPM2015Config";
  
  if( argc>1 ) {
    std::string tag_str(argv[1]);
    tag = tag_str;
    if( argc>2 ) {
      std::string config_str(argv[2]);
      config=config_str;
    }
  } else {
    std::cout << "Usage:" << std::endl;
    std::cout << "./timingStudies ([tag]) ([config])" << std::endl;
    exit(12345);
  }

  std::cout<<config<<std::endl;
  
  theConfiguration_=readConfiguration(config);
  


  std::vector<float> energies;
  std::vector<int> wp_channel;
  std::vector<int> wp_fibre;
  std::vector<int> runs;

  for (int i=0;i<theConfiguration_.energies.size();++i){
    energies.push_back(theConfiguration_.energies[i]);
    wp_channel.push_back(theConfiguration_.wp_channel[i]);
    wp_fibre.push_back(theConfiguration_.wp_fibre[i]);
    runs.push_back(theConfiguration_.runs[i]);
  }

  std::string constDirName = "plots_timing_";
  constDirName+=theConfiguration_.setup;
  system(Form("mkdir -p %s", constDirName.c_str()));
  TString dir(constDirName);

  TGraphErrors* resVsEnergy_channel = new TGraphErrors(0);
  TGraphErrors* resVsEnergy_fibre = new TGraphErrors(0);

  std::vector<TGraphErrors*> resVsAmplitude;


  for (int i=0;i<runs.size();++i){
    TString run;
    run.Form("%d",runs[i]); 
    resVsAmplitude.push_back(new TGraphErrors(0));


    TFile* file = TFile::Open(dir+"/timingStudiesSiPM_"+tag+"_"+run+".root");

    if( file==0 ) {
      std::cout << "ERROR! Din't find file for run" << runs[i] << std::endl;
      std::cout << "Exiting." << std::endl;
      exit(11);
    }
    
    //channel
    TVectorD* resValueTime_channel=(TVectorD*)file->Get("resValueTime_channel");
    TVectorD* resErrValueTime_channel=(TVectorD*)file->Get("resErrValueTime_channel");
    TVectorD* resValueAmplitude_channel=(TVectorD*)file->Get("resValueAmplitude_channel");
    TVectorD* resErrValueAmplitude_channel=(TVectorD*)file->Get("resErrValueAmplitude_channel");
    TVectorD* resErrRelativeValueTime_channel=(TVectorD*)file->Get("resErrRelativeValueTime_channel");
    TVectorD* nEntriesTime_channel=(TVectorD*)file->Get("nEntriesTime_channel");

    //fibre
    TVectorD* resValueTime_fibre=(TVectorD*)file->Get("resValueTime_fibre");
    TVectorD* resErrValueTime_fibre=(TVectorD*)file->Get("resErrValueTime_fibre");

    
    //    resVsEnergy->SetPoint( i, energies[i],(*resValueTime)[wp_100[i]] );
    //FIXME    resVsEnergy->SetPointError( i, 0, (*resErrValueTime)[wp_100[i]]);


    resVsEnergy_channel->SetPoint( i, energies[i], (*resValueTime_channel)[wp_channel[i]]);
    resVsEnergy_channel->SetPointError( i, 0,(*resErrValueTime_channel)[wp_channel[i]] );

    resVsEnergy_fibre->SetPoint( i, energies[i], (*resValueTime_fibre)[wp_fibre[i]]);
    resVsEnergy_fibre->SetPointError( i, 0,(*resErrValueTime_fibre)[wp_fibre[i]] );
 

    for (int j=0;j<resValueTime_channel->GetNoElements();j++){
      //      std::cout<<j<<" "<<(*resValueAmplitude_channel)[j]<<std::endl;
      if ((*resValueAmplitude_channel)[j]<10)continue;
      resVsAmplitude[i]->SetPoint(j,(20+j*10),(*resValueAmplitude_channel)[j]);
      resVsAmplitude[i]->SetPointError(j,0,(*resErrValueAmplitude_channel)[j]);
    }

    
  }
  

  TFile * outFile = new TFile(dir+"/plotsTimingStudiesSiPM_"+tag+".root","recreate");

  TCanvas* c1 = new TCanvas( "c1", "", 600, 600 );

  float yup=1.1*(resVsAmplitude[2]->GetY())[0];
  if((resVsAmplitude[2]->GetY())[0]<10) yup = 1.1*(resVsAmplitude[1]->GetY())[0];
  float  xlow=(resVsAmplitude[2]->GetX())[0]-10;
  if(xlow<10)xlow = (resVsAmplitude[1]->GetX())[0]-10;
  float xup=(resVsAmplitude[2]->GetX())[resVsAmplitude[2]->GetN()-1]+10; 
  if(xup<10)xup = (resVsAmplitude[2]->GetX())[resVsAmplitude[2]->GetN()-1]+10; 
  TH2D* h2_axes_2 = new TH2D( "axes_2", "", 100, xlow,xup , 110, 0., yup);

  //  std::cout<<(resVsEnergy_channel->GetY())[0]+(resVsEnergy_channel->GetErrorY(0))<<std::endl;

  TH2D* h2_axes_3 = new TH2D( "axes_1", "", 100, -0.0, 250. , 110, 60., 1.1*((resVsEnergy_channel->GetY())[0]+(resVsEnergy_channel->GetErrorY(0))));  
  h2_axes_3->SetXTitle("Beam Energy [GeV]");
  h2_axes_3->SetYTitle("time_{Fibre}-time_{mcp} [ps]");

  TH2D* h2_axes_4 = new TH2D( "axes_1", "", 100, -0.0, 250. , 110, 60., 1.1*((resVsEnergy_fibre->GetY())[0]+(resVsEnergy_fibre->GetErrorY(0))));  
  h2_axes_4->SetXTitle("Beam Energy [GeV]");
  h2_axes_4->SetYTitle("time_{Fibre}-time_{mcp} [ps]");

  
  //resolution vs energy
  //channel
  TF1* f_ene= new TF1("fun_ene","[1]/x+[0]",(resVsEnergy_channel->GetX())[0]-10,(resVsEnergy_channel->GetX())[resVsEnergy_channel->GetN()-1] +10);

  h2_axes_3->Draw("");
  resVsEnergy_channel->Fit("fun_ene");

  TLegend* lego_2 = new TLegend(0.47, 0.7, 0.8, 0.92);
  lego_2->SetTextSize(0.038);
  lego_2->AddEntry(  (TObject*)0 ,"f(x) = p0 + p1/x", "");
  lego_2->AddEntry(  (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f_ene->GetParameter(0), f_ene->GetParError(0) ), "");
  lego_2->AddEntry(  (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f_ene->GetParameter(1), f_ene->GetParError(1) ), "");
  lego_2->SetFillColor(0);
  lego_2->Draw("same");


  resVsEnergy_channel->SetMarkerStyle(20);
  resVsEnergy_channel->SetMarkerSize(1.6);
  resVsEnergy_channel->SetMarkerColor(kBlue);
  resVsEnergy_channel->Draw("p same");
  resVsEnergy_channel->SetName("resVsEnergy_channel");
  resVsEnergy_channel->Write();

  c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_channel.png");
  c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_channel.pdf");  
  //fibre
  h2_axes_4->Draw("");
  resVsEnergy_fibre->Fit("fun_ene");

  lego_2->Clear();
  lego_2->SetTextSize(0.038);
  lego_2->AddEntry(  (TObject*)0 ,"f(x) = p0 + p1/x", "");
  lego_2->AddEntry(  (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f_ene->GetParameter(0), f_ene->GetParError(0) ), "");
  lego_2->AddEntry(  (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f_ene->GetParameter(1), f_ene->GetParError(1) ), "");
  lego_2->SetFillColor(0);
  lego_2->Draw("same");


  resVsEnergy_fibre->SetMarkerStyle(20);
  resVsEnergy_fibre->SetMarkerSize(1.6);
  resVsEnergy_fibre->SetMarkerColor(kBlue);
  resVsEnergy_fibre->Draw("p same");
  resVsEnergy_fibre->SetName("resVsEnergy_fibre");
  resVsEnergy_fibre->Write();

  c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_fibre.png");
  c1->SaveAs(dir+"/timingResolutionVsEnergySiPM_fibre.pdf");  

  for(int i=0;i<runs.size();++i){ 
    TString ene;
    ene.Form("%.0f",energies[i]); 
    std::string energy(Form("%.0f", energies[i]));

    h2_axes_2->SetYTitle("#sigma_{t} [ps]");
    h2_axes_2->GetXaxis()->SetTitle("Amplitude [ADC]");
    h2_axes_2->Draw(""); 

    TF1* f= new TF1("fun","[1]/x+[0]",(resVsAmplitude[i]->GetX())[0]-10,(resVsAmplitude[i]->GetX())[resVsAmplitude[i]->GetN()-1] +10);
    resVsAmplitude[i]->Fit("fun");

    resVsAmplitude[i]->SetName("resVsAmplitude_"+ene);
    resVsAmplitude[i]->SetMarkerStyle(20);
    resVsAmplitude[i]->SetMarkerSize(1.6);
    resVsAmplitude[i]->SetMarkerColor(kBlue);
    resVsAmplitude[i]->Draw("p same");


    TPaveText* pave = DrawTools::getLabelTop_expOnXaxis(energy+" GeV Electron Beam");
    pave->Draw("same");



    TLegend* lego = new TLegend(0.47, 0.7, 0.8, 0.92);
    lego->SetTextSize(0.038);
    lego->AddEntry(  (TObject*)0 ,"f(x) = p0 + p1/x", "");
    lego->AddEntry(  (TObject*)0 ,Form("p0 = %.0f #pm %.0f", f->GetParameter(0), f->GetParError(0) ), "");
    lego->AddEntry(  (TObject*)0 ,Form("p1 = %.0f #pm %.0f", f->GetParameter(1), f->GetParError(1) ), "");
    lego->SetFillColor(0);
    lego->Draw("same");

    c1->SaveAs(dir+"/timingResolutionVsAmplitudeSiPM_"+ene+"GeV.png");
    c1->SaveAs(dir+"/timingResolutionVsAmplitudeSiPM_"+ene+"GeV.pdf");  

 

    resVsAmplitude[i]->Write();
  }

  outFile->Write();
  outFile->Close();

  return 0;

}
示例#21
0
void makePassFail_QCDMC(const string numeHistName, const string denoHistName, 
			const string title, const string HTbinlabel, 
			const string signalHistName, const string controlHistName,
			const pair<unsigned, unsigned>& jetBin,
			const float fitrange_xmin = 50, const float fitrange_xmax = 150) 
{
	incMHTBins.clear();
	for (int i=0; i<nMHTbins; ++i) incMHTBins.push_back(arrMHTbins[i]);
	const bool logScale = true;
	const float scaleTo = fDATA_LUMI; // pb-1

	TH1 *Hist_pass = GetHist(numeHistName, scaleTo);
	TH1 *Hist_fail = GetHist(denoHistName, scaleTo);

	Hist_pass->SetMarkerColor(kBlack);
	Hist_pass->SetLineColor(kBlack);
	/*new TCanvas();
	gPad->SetLogy();
	Hist_pass->SetLineColor(kRed);
	Hist_pass->SetMarkerColor(kRed);
	Hist_pass->DrawCopy();
	Hist_fail->DrawCopy("same");
	*/
	//gPad->Print("range.eps");
	cout << __LINE__ << ": Integrals= " << Hist_fail->Integral() << "/" << Hist_pass->Integral() << endl;
	if (Hist_fail->GetEntries()<1 || Hist_pass->GetEntries()<1) 
	{
		cout << __LINE__ << ": not enough intries to make the plots!!! " << Hist_fail->Integral() << "/" << Hist_pass->Integral() << endl;
		return;
	}

//	DumpHist(Hist_pass);
//	DumpHist(Hist_fail);

	Hist_pass->Divide(Hist_fail);

//	cout << ">>>>>>> AFTER DIVIDE <<<<< " << endl;
//	DumpHist(Hist_pass);
	const int maxbin = Hist_pass->GetMaximumBin();
	const double max = Hist_pass->GetBinContent(maxbin);
	//Hist_pass->GetYaxis()->SetRangeUser(-0.05, max+0.05);


	//fit range
	//const float fitrange_xmin = 50, fitrange_xmax = 120;
	stringstream newtitle;
	//newtitle << "Fit Range " << fitrange_xmin << "--" << fitrange_xmax << title;
	//newtitle << title << " (fit range = " <<  fitrange_xmin << "--" << fitrange_xmax << "), c = " << CONST_C << ";MHT [GeV];Ratio (r);";
	newtitle << title << " (fit range = " <<  fitrange_xmin << "-" << fitrange_xmax << ");MHT [GeV];Ratio (r);";


	gStyle->SetOptStat(0);	
	new TCanvas();
	//gPad->SetGridy();
	gPad->SetTickx();
	if (logScale) gPad->SetLogy();
	Hist_pass->SetLineColor(9);
	Hist_pass->SetTitle(newtitle.str().c_str());
	Hist_pass->SetLineWidth(2);

	gStyle->SetOptFit(1);
	//Hist_pass->SetStats(0);
	Hist_pass->Draw();
	//return;

	//do fittings exp and gaus
	/*float C_UPLIMIT = 0.04;
	float C_LOLIMIT = 0.02;
	if (jetBin.first == 2 && jetBin.second == 2)
	{
		C_UPLIMIT = 0.00235;
		C_LOLIMIT = 0.00232;
	} else if (jetBin.first == 3 && jetBin.second == 5)
	{
		C_UPLIMIT = 0.03;
		C_LOLIMIT = 0.025;
	} else if (jetBin.first == 6 && jetBin.second == 7)
	{
		C_UPLIMIT = 0.2;
		C_LOLIMIT = 0.17;
	} else if (jetBin.first == 8)
	{
		C_UPLIMIT = 0.4;
		C_LOLIMIT = 0.2;
	}
	*/

	const float mean_c_initial = GetAvgVal(Hist_pass, 350);

	//do fittings exp and gaus
	const float C_UPLIMIT = mean_c_initial+0.0001; //this only to get this values on the stat box
	const float C_LOLIMIT = mean_c_initial-0.0001;



	Hist_pass->SetMinimum(C_LOLIMIT/10);


	TF1 *expFit=new TF1("fit_1",expFitFunc,fitrange_xmin,fitrange_xmax,3);
	expFit->SetParameter(0,0.09);
	expFit->SetParameter(1,-0.0002);
	expFit->SetParameter(2,CONST_C);
	expFit->SetParLimits(2,C_LOLIMIT, C_UPLIMIT);
	Hist_pass->Fit(expFit,"E0","",fitrange_xmin, fitrange_xmax);
	gPad->Modified();
	gPad->Update();
	TPaveStats *e_stats = (TPaveStats*) Hist_pass->FindObject("stats");
	e_stats->SetTextColor(kRed);
	TPaveStats *exp_stats = (TPaveStats*) e_stats->Clone("exp_stats");

	TF1 *expFit2=new TF1("fit_2",expFitFunc,50,1000.0,3);
	expFit2->SetParameter(0,expFit->GetParameter(0));
	expFit2->SetParameter(1,expFit->GetParameter(1));
	expFit2->SetParameter(2,expFit->GetParameter(2));
	expFit2->SetLineColor(kRed+1);
	expFit2->SetLineWidth(2);

	//for unceratinty on c
	TF1 *expFit_sigma = new TF1("Exp_sigma",expFitFunc_Cup,50,1000.0,3);
	expFit_sigma->SetParameter(0,expFit->GetParameter(0));
	expFit_sigma->SetParameter(1,expFit->GetParameter(1));
	expFit_sigma->SetParameter(2,expFit->GetParameter(2)); //%100 error
	expFit_sigma->SetParLimits(2,C_LOLIMIT/2., C_UPLIMIT*2.);
	Hist_pass->Fit(expFit_sigma,"E0","",fitrange_xmin, fitrange_xmax);


	TF1 *gausFit=new TF1("fit_3",gausFitFunc,fitrange_xmin, fitrange_xmax,3);
	gausFit->SetParameter(0,0.09); 
	gausFit->SetParameter(1,-0.0002);
	gausFit->SetParameter(2,CONST_C);
	gausFit->SetParLimits(2,C_LOLIMIT,C_UPLIMIT);
	gausFit->SetLineColor(kGreen-2);
	Hist_pass->Fit(gausFit,"E0","", fitrange_xmin, fitrange_xmax);
	gPad->Modified();
	gPad->Update();
	TPaveStats *gaus_stats = (TPaveStats*) Hist_pass->FindObject("stats");
	gaus_stats->SetTextColor(kGreen);
	//TPaveStats *gaus_stats = (TPaveStats*) g_stats->Clone("gaus_stats");

	//TF1 *gausFit2=new TF1("fit_4",gausFitFunc,50,1000.0,2);
	TF1 *gausFit2=new TF1("fit_4",gausFitFunc,50,1000.0,3);
	gausFit2->SetParameter(0,gausFit->GetParameter(0)); 
	gausFit2->SetParameter(1,gausFit->GetParameter(1));
	gausFit2->SetParameter(2,gausFit->GetParameter(2));
	gausFit2->SetLineColor(kGreen);
	gausFit2->SetLineWidth(2);

	//for unceratinty on c
	TF1 *gausFit_sigma=new TF1("Gaus_sigma",gausFitFunc_Cup,50,1000.0,3);
	gausFit_sigma->SetParameter(0,gausFit->GetParameter(0)); 
	gausFit_sigma->SetParameter(1,gausFit->GetParameter(1));
	gausFit_sigma->SetParameter(2,gausFit->GetParameter(2) * 2); //100% error
	gausFit_sigma->SetParLimits(2,C_LOLIMIT/2., C_UPLIMIT*2.);
	Hist_pass->Fit(gausFit_sigma,"E0","", fitrange_xmin, fitrange_xmax);


	gausFit2->Draw("same");
	expFit2->Draw("same");
	/*gausFit_sigma->SetLineStyle(10);
	gausFit_sigma->SetLineColor(gausFit2->GetLineColor());
	expFit_sigma->SetLineStyle(10);
	expFit_sigma->SetLineWidth(2);
	expFit_sigma->SetLineColor(expFit2->GetLineColor());
	gausFit_sigma->Draw("same");
	expFit_sigma->Draw("same");
*/
	//TLegend *leg  = new TLegend(0.7,0.8,0.9,0.9);
	TLegend *leg  = new TLegend(0.7,0.7,0.9,0.9);
	leg->AddEntry(gausFit2,"Gaussian");
	leg->AddEntry(expFit2,"Exponential");
	leg->SetTextFont(42);
	leg->Draw();

	const float xmin=0.2, xmax=0.45, ymin=0.7, ymax=0.9;
	gaus_stats->SetX1NDC(xmin);
	gaus_stats->SetX2NDC(xmax);
	gaus_stats->SetY1NDC(ymin);
	gaus_stats->SetY2NDC(ymax);
	gaus_stats->Draw("same");
	exp_stats->SetX1NDC(xmax);
	exp_stats->SetX2NDC(xmax+0.25);
	exp_stats->SetY1NDC(ymin);
	exp_stats->SetY2NDC(ymax);
	exp_stats->Draw("same");

	//fit quality
	stringstream gaus_fit_res, exp_fit_res;
	const float gausFit_goodness =  gausFit->GetChisquare()/gausFit->GetNDF();
	gaus_fit_res << "#chi^{2}/ndof = " << gausFit->GetChisquare()
			 << "/"<< gausFit->GetNDF() << " = " << gausFit_goodness;
	const float expFit_goodness =  expFit->GetChisquare()/expFit->GetNDF();
	exp_fit_res << "#chi^{2}/ndof = " << expFit->GetChisquare()
			 << "/"<< expFit->GetNDF() << " = " << expFit_goodness;

	cout << gaus_fit_res.str() << endl;
	cout << exp_fit_res.str() << endl;

	TPaveText *pt1 = new TPaveText(0.5,0.8,0.7,0.9);
	pt1->AddText(gaus_fit_res.str().c_str());
	pt1->AddText(exp_fit_res.str().c_str());
//	pt1->Draw("same");

	//stringstream epsname;
	//epsname << "factnomht/HTbin" << HTbin << "_fitrange_" << fitrange_xmin << "to" << fitrange_xmax << ".eps";
	//epsname << "factnomht_" << HTbinlabel << ".eps";
	//gPad->Print(epsname.str().c_str());
	gPad->Print("ratios.eps");
	//return;

	 //make a predicion
	TH1 *sigHist      = GetHist(signalHistName, scaleTo);
	TH1 *controlHist  = GetHist(controlHistName, scaleTo);

	//temp hack to get # of bins the same for easy debugging
	sigHist->Rebin(2);

	cout << red << "sigHist/controlHist bins = " << sigHist->GetNbinsX() << "/" << controlHist->GetNbinsX() << clearatt << endl; 
//	new TCanvas();
//	sigHist->SetLineColor(kRed);
//	sigHist->Rebin(50);
//	controlHist->Rebin(50);
//	sigHist->Draw();
//	controlHist->Draw("same");


	//collect results
/*	Predictions_t pred_gaus       = GetPredictions(controlHist, gausFit2, sigHist); 
	Predictions_t pred_gaus_sigma = GetPredictions(controlHist, gausFit_sigma, sigHist); 
	Predictions_t pred_exp        = GetPredictions(controlHist, expFit2, sigHist); 
	Predictions_t pred_exp_sigma  = GetPredictions(controlHist, expFit_sigma, sigHist); 

//	PrintExclResults(pred_gaus);
//	PrintExclResults(pred_exp);
	PrintExclResults(pred_gaus, pred_exp, pred_gaus_sigma, pred_exp_sigma);
*/
	/*****************************************/
	// TEMP HACK TO GET RESULTS for all HT bins 
	// using these inclusive fits
	/*****************************************/
	vector<pair<float, float> > htBins_temp;
	pair<float, float> htbin1(500,750);	
	pair<float, float> htbin2(750,1000);	
	pair<float, float> htbin3(1000,1250);	
	pair<float, float> htbin4(1250,1500);	
	pair<float, float> htbin5(1500,8000);	

	htBins_temp.push_back(htbin1);
	htBins_temp.push_back(htbin2);
	htBins_temp.push_back(htbin3);
	htBins_temp.push_back(htbin4);
	htBins_temp.push_back(htbin5);

	TFile file("qcd_all.root");
	if (file.IsZombie()) 
	{ 
		cout << __FUNCTION__ << ":" << __LINE__ 
				<< "File to get exlcusive HT prediction is not found!" << endl;assert (false);
	}

	for (unsigned htbin=0; htbin<htBins_temp.size(); ++htbin)
	{
		stringstream folder, control_hist_name, signal_hist_name;
		folder << "Hist/Njet" << jetBin.first << "to" << jetBin.second 
			<< "HT"   << htBins_temp.at(htbin).first << "to" << htBins_temp.at(htbin).second 
			<< "MHT0to8000";
		control_hist_name << folder.str() << "/smeared_failFineBin1"; 
		signal_hist_name << folder.str() << "/smear_signalFineBin"; 
		TH1* control_hist = (TH1*) (file.Get(control_hist_name.str().c_str())); 
		if (control_hist == NULL) { 
			cout << __LINE__ << ": control hist " << control_hist_name.str() << " not found for htbin " << htBins_temp.at(htbin).first 
				<< "-" << htBins_temp.at(htbin).second << endl; 
			assert(false);		
		} 
		TH1* signal_hist = (TH1*) (file.Get(signal_hist_name.str().c_str())); 
		if (signal_hist == NULL) { cout << __LINE__ << ": signal hist not found for htbin " << htBins_temp.at(htbin).first << "-" << htBins_temp.at(htbin).second << endl; } 

		control_hist->Print();
		signal_hist->Print();

		//temp hack to get # of bins the same for easy debugging
		signal_hist->Rebin(2);

		Predictions_t pred_gaus       = GetPredictions(control_hist, gausFit2, signal_hist); 
		Predictions_t pred_gaus_sigma = GetPredictions(control_hist, gausFit_sigma, signal_hist); 
		Predictions_t pred_exp        = GetPredictions(control_hist, expFit2, signal_hist); 
		Predictions_t pred_exp_sigma  = GetPredictions(control_hist, expFit_sigma, signal_hist); 

		cout << ">>>>>>>>>>>>>>> PREDICTIONS FOR " << jetBin.first << "-" << jetBin.second 
					<< ", HT=" << htBins_temp.at(htbin).first << "-" << htBins_temp.at(htbin).second << endl;
		PrintExclResults(pred_gaus, pred_exp, pred_gaus_sigma, pred_exp_sigma);
	}

	file.Close();

}
示例#22
0
文件: plotvn.C 项目: XuQiao/phenix
void plotvn(){
    gStyle->SetOptStat(kFALSE);
    int icent = 0;
    int n = 2;
    int color[6] = {1,2,5,4,7,8};
    int style[12] = {20,21,24,25,26,27,29,30,31,32,33,34};
    TGraphErrors *gr[nsub][3][2];
    TGraphErrors *grraw[nsub][3][2];
    TString CNTEP, dire;
    for(int isub=0;isub<nsub;isub++){
    for(int idire=0;idire<3;idire++){
    for(int iCNTEP=0;iCNTEP<2;iCNTEP++){
        if(iCNTEP==0) CNTEP = "NoUseCNTEP";
        if(iCNTEP==1) CNTEP = "UseCNTEP";
        if(idire==0) dire = "";
        if(idire==1) dire = "_east";
        if(idire==2) dire = "_west";
        TString str = choosesub(isub);
        if(str=="ABORT") continue;
        gr[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%d_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg");
        grraw[isub][idire][iCNTEP] = new TGraphErrors(Form("Result/%s/v%draw_00_%d%s_%s.dat",CNTEP.Data(),n,icent,dire.Data(),str.Data()),"%lg %lg %lg");
        SetStyle(*gr[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]);
        SetStyle(*grraw[isub][idire][iCNTEP], 1.2, color[idire+3*iCNTEP],style[isub]);
    }
    }
    }
TH1F* h = new TH1F("h","",50,0,5);
h->GetXaxis()->SetRangeUser(0,3.2);
/*
TCanvas *c1 = new TCanvas("c1","c1",800,450);
iCNTEP = 0;
idire = 0;
c1->Divide(2);
c1->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
h->GetXaxis()->SetRangeUser(0,3.2);
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
for(int ilay = 0;ilay<4;ilay++){
leg->AddEntry(gr[ilay+8][idire][iCNTEP],Form("FVTX layer %d",ilay));
gr[ilay+8][idire][iCNTEP]->Draw("Psame");
}
gr[6][0][1]->Draw("Psame");
leg->AddEntry(gr[6][idire][iCNTEP],Form("FVTX -3.0<#eta<-1.0"));
leg->Draw("Psame");

c1->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
for(int ilay = 0;ilay<4;ilay++){
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[ilay+8][idire][iCNTEP],gr[6][idire][iCNTEP]);
SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[ilay+8]);
grr->Draw("Psame");
}
*/
TCanvas *c2 = new TCanvas("c2","c2",800,450);
iCNTEP = 0;
idire = 0;
c2->Divide(2);
c2->cd(1);
if(n==2){
h->SetMinimum(0);
h->SetMaximum(0.3);
}
//SetTitle(h,"","p_{T}","v_{2}^{raw}");
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[1][idire][iCNTEP]->Draw("Psame");
gr[2][idire][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[2][idire][iCNTEP],Form("BBCs"));
leg->AddEntry(gr[6][idire][iCNTEP],Form("FVTXs tracks -3.0<#eta<-1.0"));
leg->Draw("Psame");

c2->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio BBCs/FVTXs");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[1][idire][iCNTEP],gr[2][idire][iCNTEP]);
SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[2]);
grr->Draw("Psame");

TCanvas *c3 = new TCanvas("c3","c3",800,450);
idire = 0;
isub=2;
c3->Divide(2);
c3->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(h,"","p_{T}","v_{2}^{raw}");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[isub][idire][1]->Draw("Psame");
gr[isub][idire][0]->Draw("Psame");
leg->AddEntry(gr[isub][idire][1],Form("FVTXs -3.0<#eta<-1.0"));
leg->AddEntry(gr[isub][idire][1],Form("Using Psi EP"),"P");
leg->AddEntry(gr[isub][idire][0],Form("Using phi EP"),"P");
leg->Draw("Psame");

c3->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs using phi EP/using Psi EP");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][idire][0],gr[isub][idire][1]);
SetStyle(*grr,1.2,color[idire+3*0],style[isub]);
grr->Draw("Psame");

TCanvas *c4 = new TCanvas("c4","c4",800,450);
isub=2;
iCNTEP = 0;
c4->Divide(2);
c4->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.05);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs tracks -3.0<#eta<-1.0"));
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c4->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs E/W");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");

TCanvas *c5 = new TCanvas("c5","c5",800,450);
isub=2;
iCNTEP = 1;
c5->Divide(2);
c5->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.012);
SetTitle(h,"","p_{T}","v_{2}^{raw}");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetTextSize(0.05);
leg->SetFillColor(0);
leg->SetBorderSize(0);
grraw[isub][0][iCNTEP]->Draw("Psame");
grraw[isub][1][iCNTEP]->Draw("Psame");
grraw[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(grraw[isub][0][iCNTEP],Form("Using BBC event plane"));
leg->AddEntry(grraw[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(grraw[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(grraw[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c5->cd(2);
h->SetMinimum(0);
h->SetMaximum(2.);
SetTitle(h,"","p_{T}","v_{2} ratio BBCs E/W");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(grraw[isub][1][iCNTEP],grraw[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");


TCanvas *c6 = new TCanvas("c6","c6",800,450);
isub=3;
iCNTEP = 0;
c6->Divide(2);
c6->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.05);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs tracks -3.0<#eta<-1.0"),"");
leg->AddEntry(gr[isub][0][iCNTEP],Form("Yellow = 5.2mrad, Blue = 1.6mrad"),"");
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c6->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs E/W");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");


TCanvas *c7 = new TCanvas("c7","c7",800,450);
isub=4;
iCNTEP = 0;
c7->Divide(2);
c7->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.05);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs tracks -3.0<#eta<-1.0"),"");
leg->AddEntry(gr[isub][0][iCNTEP],Form("Yellow = 3.6mrad, Blue = 1.6mrad"),"");
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c7->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs E/W");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
}
void CumulantErrGraph_v2_normalized(){

	TFile *f;

	const int NAchBins = 7;

	TH1D* c2_pos[NAchBins][2];
	TH1D* c2_neg[NAchBins][2];

	TH1D* ach_hist[NAchBins];
	double x[NAchBins];

	double v2_pos[NAchBins];
	double v2_neg[NAchBins];
	double v2_diff[NAchBins];
	double err_neg[NAchBins];
	double err_pos[NAchBins];
	double err_diff[NAchBins];
	double cmean;
	double errmean;
	double sum;
	double variance_pos;
	double variance_neg;
	double variance_diff;

	int low = 60;
	int upp = 90;


	f = new TFile(Form("../../../rootfiles/crosscheck/PbPb/v3/%d_%d/Merged.root",low,upp));
	TLatex* text_b = makeLatex(Form("centrality %d-%d",low,upp),0.25,0.88) ;



	for (Int_t i = 0; i < NAchBins; i++){
		ach_hist[i] = (TH1D*)f->Get(Form("demo/ach_%d",i+1));

		c2_pos[i][0] = (TH1D*)f->Get(Form("demo/c2pos_%d_cos",i));
		c2_pos[i][1] = (TH1D*)f->Get(Form("demo/c2pos_%d_sin",i));

		c2_neg[i][0] = (TH1D*)f->Get(Form("demo/c2neg_%d_cos",i));
		c2_neg[i][1] = (TH1D*)f->Get(Form("demo/c2neg_%d_sin",i));
		
	}
	for(Int_t i=0; i<NAchBins; i++){

		x[i]=ach_hist[i]->GetMean();

//v2 positive
		cmean = c2_pos[i][0] -> GetMean();
		v2_pos[i] = sqrt(cmean);

		errmean = c2_pos[i][0] -> GetMeanError();
		variance_pos = (errmean*errmean)/(4*cmean);

//negative
		cmean = c2_neg[i][0] -> GetMean();
		v2_neg[i] = sqrt(cmean);

		errmean = c2_neg[i][0] -> GetMeanError();
		variance_neg = (errmean*errmean)/(4*cmean);

		//difference
		v2_diff[i] = (v2_neg[i] - v2_pos[i])/(v2_neg[i] + v2_pos[i]);

		sum = v2_pos[i] + v2_neg[i];

		variance_diff = (4*v2_neg[i]*v2_neg[i]*variance_pos)/(sum*sum*sum*sum)+(4*v2_pos[i]*v2_pos[i]*variance_neg)/(sum*sum*sum*sum);


	//error bars

		err_pos[i] = sqrt(variance_pos);
		err_neg[i] = sqrt(variance_neg);
		err_diff[i] = sqrt(variance_diff);


	}
	cout << low << upp << endl;
	for(i=0;i<NAchBins;i++){
		cout << x[i] << ", ";
	}	
	cout << endl << "v2" << endl;
	for(i=0;i<NAchBins;i++){
		cout << v2_diff[i] << ", ";
	}
	cout << endl << "v2 error" <<endl;
	for(i=0;i<NAchBins;i++){
		cout << "error is: " << err_pos[i] << endl;
	}		
	gStyle->SetLegendFont(42);
	TH1D* base = new TH1D("base","base",1,-0.3,0.3);
	//pPb
	//base->GetYaxis()->SetRangeUser(0.065, 0.075);

	//PbPb
	base->GetYaxis()->SetRangeUser(0.018, 0.03);
	base->GetXaxis()->SetTitle("Observed A_{ch}");
	base->GetYaxis()->SetTitle("v_{3}{2}");
	base->GetXaxis()->CenterTitle();
	base->GetYaxis()->CenterTitle();
	base->SetTitleSize  (0.040,"X");
	base->SetTitleOffset(1.4,"X");
	base->SetTitleFont  (42,"X");
	base->SetLabelOffset(0.006,"X");
	base->SetLabelSize  (0.040,"X");
	base->SetLabelFont  (42   ,"X");

	base->SetTitleSize  (0.040,"Y");
	base->SetTitleOffset(2.2,"Y");
	base->SetTitleFont  (42,"Y");
	base->SetLabelOffset(0.006,"Y");
	base->SetLabelSize  (0.040,"Y");
	base->SetLabelFont  (42   ,"Y");
	base->SetLineWidth(0);

	TH1D* base2 = new TH1D("base2","base2",1,-0.4,0.4);
	base2->GetYaxis()->SetRangeUser(-0.06, 0.06);
	base2->GetXaxis()->SetTitle("Observed A_{ch}");
	base2->GetYaxis()->SetTitle(" #frac{ v_{3}^{#minus} #minus v_{3}^{#plus} }{ v_{3}^{#minus} #plus v_{3}^{#plus} } ");
	base2->GetXaxis()->CenterTitle();
	base2->GetYaxis()->CenterTitle();
	base2->SetTitleSize  (0.040,"X");
	base2->SetTitleOffset(1.4,"X");
	base2->SetTitleFont  (42,"X");
	base2->SetLabelOffset(0.006,"X");
	base2->SetLabelSize  (0.040,"X");
	base2->SetLabelFont  (42   ,"X");
	base2->SetTitleSize  (0.040,"Y");
	base2->SetTitleOffset(2.0,"Y");
	base2->SetTitleFont  (42,"Y");
	base2->SetLabelOffset(0.006,"Y");
	base2->SetLabelSize  (0.040,"Y");
	base2->SetLabelFont  (42   ,"Y");
	base2->SetLineWidth(0);

	TFile *rebinned = new TFile("~/Summer2016/root_forgraphs/figure2_1.root","RECREATE");

	TGraphErrors *gr_pos = new TGraphErrors(NAchBins,x,v2_pos,NULL,err_pos);
	TGraphErrors *gr_neg = new TGraphErrors(NAchBins,x,v2_neg,NULL,err_neg);
	TGraphErrors *gr_diff = new TGraphErrors(NAchBins,x,v2_diff,NULL,err_diff);

	gr_pos->Write();
	gr_neg->Write();
	gr_diff->Write();



 //   TCanvas* c1 = new TCanvas("c1","c1");
 //   TCanvas* c2 = new TCanvas("c2","c2");
	TCanvas* c3 = new TCanvas("c3","c3",1,1,1200,600);
	c3->Divide(2,1,0.01,0.01);

	gr_neg -> SetMarkerStyle(20);
	gr_neg -> SetMarkerColor(kBlue);
	gr_pos -> SetMarkerStyle(34);	
	gr_pos -> SetMarkerColor(kRed);




	TLatex* text_a = makeLatex("CMS PbPb #sqrt{s_{NN}}=5.02TeV",0.25,0.85) ;
	//TLatex* text_b = makeLatex("185 #leq N_{trk}^{offline} < 260",0.25,0.80) ;

	TLatex* text_c = makeLatex("0.3 < p_{T} < 3 GeV/c",0.25,0.75) ;
	TLatex* text_d = makeLatex("|#Delta#eta| > 2",0.25,0.70) ;

	text_a->SetTextFont(42);
	text_b->SetTextFont(42);
	text_c->SetTextFont(42);
	text_d->SetTextFont(42);



	TLegend* leg = new TLegend(0.76,0.80,0.94,.88);
	leg->SetLineColor(kWhite);
	leg->SetFillColor(0);
	leg->SetFillStyle(0);
	leg->AddEntry(gr_pos, "v_{3}^{#plus}{2}","p");
	leg->AddEntry(gr_neg , "v_{3}^{#minus}{2}","p");



	c3->cd(1);
	base->Draw("");
	gr_pos->Draw("PSame");
	gr_neg->Draw("PSame");
	//text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	//text_c->DrawClone("Same");
	//text_d->DrawClone("Same");

	leg->DrawClone("Same");


    //Define a linear function
	TF1* fit1 = new TF1("f1", "[0]+x*[1]", -0.2, 0.2);
	fit1->SetLineColor(kRed);
	fit1->SetLineStyle(2);
	gr_diff->Fit(fit1,"N0");
	fit1->Write();
	rebinned->Close();



	c3->cd(2);



	TLatex* text2 = makeLatex(Form("Intercept : %f #pm %f",fit1->GetParameter(0),fit1->GetParError(0)),0.45,0.30) ;
	TLatex* text1 = makeLatex(Form("slope : %.3f #pm %.3f",fit1->GetParameter(1),fit1->GetParError(1)),0.45,0.25) ;
	text1->SetTextFont(42);
	text2->SetTextFont(42);
	base2->Draw("");
	fit1->DrawClone("Same");
	gr_diff->SetMarkerStyle(20);
	gr_diff->Draw("PSame");

	//text_a->DrawClone("Same");
	text_b->DrawClone("Same");
	

	text1->DrawClone("Same");
	text2->DrawClone("Same");

	

	TF1 *fa1 = new TF1("fa1","0",-10,10); 
	fa1->SetLineColor(kBlack);
	fa1->SetLineWidth(0);
	fa1->DrawClone("Same");

	TLegend* leg2 = new TLegend(0.25,0.68,0.5,0.78);
	leg2->SetLineColor(kWhite);
	leg2->SetFillColor(0);
	leg2->SetFillStyle(0);
	leg2->AddEntry(fit1, "Linear fit","l");
	leg2->AddEntry(gr_diff , "data","p");
	leg2->DrawClone("Same");

	SaveCanvas(c3,"pics",Form("PbPb_crosscheck_v3_%d_%d",low,upp));




}
示例#24
0
// examples macro
void 
mutauAfterFit_novbf(bool scaled = true, bool log = true)
{
  // defining the common canvas, axes pad styles
  SetStyle();

  // open example histogram file
  TFile* exampleFile = new TFile("root/muTau_sm.root");

  //load example histograms
  TH1F* data = (TH1F*)exampleFile->Get("muTau_SM0/data_obs");
  if(data) {InitHist(data, "#bf{m_{vis} [GeV]}", "#bf{Events}"); InitData(data);} else{std::cout << "can't find hitogram " << "muTau_SM0/data_obs" << std::endl;}

  TH1F* Fakes =  refill((TH1F*)exampleFile->Get("muTau_SM0/QCD"))              ; InitHist(Fakes, "", "", kMagenta-10, 1001);                   
  TH1F* EWK1  =  refill((TH1F*)exampleFile->Get("muTau_SM0/W"  ))              ; InitHist(EWK1 , "", "", kRed    + 2, 1001);
  TH1F* EWK2  =  refill((TH1F*)exampleFile->Get("muTau_SM0/ZJ" ))              ; InitHist(EWK2 , "", "", kRed    + 2, 1001);
  TH1F* EWK3  =  refill((TH1F*)exampleFile->Get("muTau_SM0/ZL" ))              ; InitHist(EWK3 , "", "", kRed    + 2, 1001);
  TH1F* EWK   =  refill((TH1F*)exampleFile->Get("muTau_SM0/VV" ))              ; InitHist(EWK  , "", "", kRed    + 2, 1001);
  TH1F* ttbar =  refill((TH1F*)exampleFile->Get("muTau_SM0/TT" ))              ; InitHist(ttbar, "", "", kBlue   - 8, 1001);
  TH1F* Ztt   =  refill((TH1F*)exampleFile->Get("muTau_SM0/ZTT"))              ; InitHist(Ztt  , "", "", kOrange - 4, 1001);
  TH1F* ggH   =  refill((TH1F*)exampleFile->Get("muTau_SM0/SM120" ))           ; InitSignal(ggH); ggH ->Scale(10*1);
  TH1F* qqH   =  refill((TH1F*)exampleFile->Get("muTau_SM0/VBF120"))           ; InitSignal(qqH); qqH ->Scale(10*1);
 
  if(scaled){
    rescale(Fakes, 2); 
    rescale(EWK1 , 3); 
    rescale(EWK2 , 4); 
    rescale(EWK3 , 5); 
    rescale(EWK  , 7); 
    rescale(ttbar, 6); 
    rescale(Ztt  , 1);
    rescale(ggH  , 8); 
    rescale(qqH  , 9);  
  }
  if(log){
    qqH  ->Add(ggH  );
    Fakes->Add(qqH  );
    EWK1 ->Add(Fakes);
    EWK2 ->Add(EWK1 );
    EWK3 ->Add(EWK2 );
    EWK  ->Add(EWK3 );
    ttbar->Add(EWK  );
    Ztt  ->Add(ttbar);
  }
  else{
    EWK1 ->Add(Fakes);
    EWK2 ->Add(EWK1 );
    EWK3 ->Add(EWK2 );
    EWK  ->Add(EWK3 );
    ttbar->Add(EWK  );
    Ztt  ->Add(ttbar);
    ggH  ->Add(Ztt  );
    qqH  ->Add(ggH  );
  }
  // define canvas
  TCanvas *canv = MakeCanvas("canv", "histograms", 600, 600);

  canv->cd();
  if(log){
    canv->SetLogy(1);
    data->SetMinimum(5.0);
    data->SetMaximum(10000000.);
  }
  else{
    data->SetMaximum(14000.);
  }
  data->SetNdivisions(505);
  data->Draw("e");

  if(log){
    Ztt->Draw("same");
    ttbar->Draw("same");
    EWK->Draw("same");
    Fakes->Draw("same");
    qqH->Draw("same");
  }
  else{
    qqH->Draw("same");
    Ztt->Draw("same");
    ttbar->Draw("same");
    EWK->Draw("same");
    Fakes->Draw("same");
  }
  data->Draw("esame");
  canv->RedrawAxis();

  CMSPrelim("#tau_{#mu}#tau_{h}", 0.45, 0.75);
  
  TLegend* leg = new TLegend(0.45, 0.45, 0.9, 0.75);
  SetLegendStyle(leg);
  leg->AddEntry(qqH  , "(10x) H#rightarrow#tau#tau" , "L" );
  leg->AddEntry(data , "Observed"                , "LP");
  leg->AddEntry(Ztt  , "Z#rightarrow#tau#tau"    , "F" );
  leg->AddEntry(ttbar, "t#bar{t}"                , "F" );
  leg->AddEntry(EWK  , "Electroweak"             , "F" );
  leg->AddEntry(Fakes, "QCD"                     , "F" );
  leg->Draw();

  TPaveText* mssm  = new TPaveText(0.78, 0.70, 0.90, 0.74, "NDC");
  mssm->SetBorderSize(   0 );
  mssm->SetFillStyle(    0 );
  mssm->SetTextAlign(   12 );
  mssm->SetTextSize ( 0.04 );
  mssm->SetTextColor(    1 );
  mssm->SetTextFont (   62 );
  mssm->AddText("m_{H}=120");
  mssm->Draw();

  if(log){
    if(scaled) canv->Print("mutau_rescaled_novbf_LOG.pdf"); else canv->Print("mutau_unscaled_novbf_LOG.pdf");
    if(scaled) canv->Print("mutau_rescaled_novbf_LOG.png"); else canv->Print("mutau_unscaled_novbf_LOG.png");

  }
  else{
    if(scaled) canv->Print("mutau_rescaled_novbf.pdf");     else canv->Print("mutau_unscaled_novbf.pdf");
    if(scaled) canv->Print("mutau_rescaled_novbf.png");     else canv->Print("mutau_unscaled_novbf.png");
  }
}
示例#25
0
void METopt()
{
//=========Macro generated from canvas: METopt/METopt
//=========  (Mon Nov 23 12:45:00 2015) by ROOT version6.02/05
   TCanvas *METopt = new TCanvas("METopt", "METopt",140,162,700,700);
   METopt->Range(-0.375,-6.432596,3.375,0.05191559);
   METopt->SetFillColor(0);
   METopt->SetBorderMode(0);
   METopt->SetBorderSize(2);
   METopt->SetLogy();
   METopt->SetFrameBorderMode(0);
   METopt->SetFrameBorderMode(0);
   
   THStack *METopt = new THStack();
   METopt->SetName("METopt");
   METopt->SetTitle("METopt");
   
   TH1F *METopt_stack_8 = new TH1F("METopt_stack_8","METopt",15,0,3);
   METopt_stack_8->SetMinimum(1.643823e-06);
   METopt_stack_8->SetMaximum(0.2532004);
   METopt_stack_8->SetDirectory(0);
   METopt_stack_8->SetStats(0);

   Int_t ci;      // for color index setting
   TColor *color; // for color definition with alpha
   ci = TColor::GetColor("#000099");
   METopt_stack_8->SetLineColor(ci);
   METopt_stack_8->GetXaxis()->SetTitle("METopt");
   METopt_stack_8->GetXaxis()->SetLabelFont(42);
   METopt_stack_8->GetXaxis()->SetLabelSize(0.035);
   METopt_stack_8->GetXaxis()->SetTitleSize(0.035);
   METopt_stack_8->GetXaxis()->SetTitleFont(42);
   METopt_stack_8->GetYaxis()->SetTitle("Events/pb");
   METopt_stack_8->GetYaxis()->SetLabelFont(42);
   METopt_stack_8->GetYaxis()->SetLabelSize(0.035);
   METopt_stack_8->GetYaxis()->SetTitleSize(0.035);
   METopt_stack_8->GetYaxis()->SetTitleFont(42);
   METopt_stack_8->GetZaxis()->SetLabelFont(42);
   METopt_stack_8->GetZaxis()->SetLabelSize(0.035);
   METopt_stack_8->GetZaxis()->SetTitleSize(0.035);
   METopt_stack_8->GetZaxis()->SetTitleFont(42);
   METopt->SetHistogram(METopt_stack_8);
   
   
   TH1D *METopt36 = new TH1D("METopt36","MET/p_{T}^{lead jet}",15,0,3);
   METopt36->SetBinContent(1,0.00068069);
   METopt36->SetBinContent(2,0.00952966);
   METopt36->SetBinContent(3,0.06912243);
   METopt36->SetBinContent(4,0.01104153);
   METopt36->SetBinContent(5,0.01663754);
   METopt36->SetBinContent(6,0.02495631);
   METopt36->SetBinError(1,0.00068069);
   METopt36->SetBinError(2,0.002546909);
   METopt36->SetBinError(3,0.02217717);
   METopt36->SetBinError(4,0.00842943);
   METopt36->SetBinError(5,0.01176452);
   METopt36->SetBinError(6,0.01440853);
   METopt36->SetEntries(48);

   ci = TColor::GetColor("#00cc00");
   METopt36->SetFillColor(ci);

   ci = TColor::GetColor("#00cc00");
   METopt36->SetLineColor(ci);

   ci = TColor::GetColor("#00cc00");
   METopt36->SetMarkerColor(ci);
   METopt36->SetMarkerStyle(22);
   METopt36->GetXaxis()->SetTitle("METopt");
   METopt36->GetXaxis()->SetLabelFont(42);
   METopt36->GetXaxis()->SetLabelSize(0.035);
   METopt36->GetXaxis()->SetTitleSize(0.035);
   METopt36->GetXaxis()->SetTitleFont(42);
   METopt36->GetYaxis()->SetTitle("Events/pb");
   METopt36->GetYaxis()->SetLabelFont(42);
   METopt36->GetYaxis()->SetLabelSize(0.035);
   METopt36->GetYaxis()->SetTitleSize(0.035);
   METopt36->GetYaxis()->SetTitleFont(42);
   METopt36->GetZaxis()->SetLabelFont(42);
   METopt36->GetZaxis()->SetLabelSize(0.035);
   METopt36->GetZaxis()->SetTitleSize(0.035);
   METopt36->GetZaxis()->SetTitleFont(42);
   METopt->Add(METopt,"");
   
   TH1D *METopt37 = new TH1D("METopt37","MET/p_{T}^{lead jet}",15,0,3);
   METopt37->SetBinContent(1,1.392893e-05);
   METopt37->SetBinContent(2,0.001351916);
   METopt37->SetBinContent(3,0.009267276);
   METopt37->SetBinContent(4,0.04333138);
   METopt37->SetBinContent(5,0.1226104);
   METopt37->SetBinContent(6,0.1345744);
   METopt37->SetBinContent(7,0.1072757);
   METopt37->SetBinContent(8,0.0786938);
   METopt37->SetBinContent(9,0.04683283);
   METopt37->SetBinContent(10,0.0271465);
   METopt37->SetBinContent(11,0.0117321);
   METopt37->SetBinContent(12,0.007680578);
   METopt37->SetBinContent(13,0.003504385);
   METopt37->SetBinContent(14,0.002544782);
   METopt37->SetBinContent(15,0.001871985);
   METopt37->SetBinContent(16,0.002029317);
   METopt37->SetBinError(1,1.392893e-05);
   METopt37->SetBinError(2,0.0001372687);
   METopt37->SetBinError(3,0.0003814526);
   METopt37->SetBinError(4,0.001364947);
   METopt37->SetBinError(5,0.003448717);
   METopt37->SetBinError(6,0.004099139);
   METopt37->SetBinError(7,0.004180275);
   METopt37->SetBinError(8,0.004584045);
   METopt37->SetBinError(9,0.003621192);
   METopt37->SetBinError(10,0.002726748);
   METopt37->SetBinError(11,0.001513075);
   METopt37->SetBinError(12,0.001337888);
   METopt37->SetBinError(13,0.001122201);
   METopt37->SetBinError(14,0.001068918);
   METopt37->SetBinError(15,0.001029262);
   METopt37->SetBinError(16,0.001037471);
   METopt37->SetEntries(12325);

   ci = TColor::GetColor("#00ffff");
   METopt37->SetFillColor(ci);

   ci = TColor::GetColor("#00ffff");
   METopt37->SetLineColor(ci);

   ci = TColor::GetColor("#00ffff");
   METopt37->SetMarkerColor(ci);
   METopt37->SetMarkerStyle(20);
   METopt37->GetXaxis()->SetTitle("METopt");
   METopt37->GetXaxis()->SetLabelFont(42);
   METopt37->GetXaxis()->SetLabelSize(0.035);
   METopt37->GetXaxis()->SetTitleSize(0.035);
   METopt37->GetXaxis()->SetTitleFont(42);
   METopt37->GetYaxis()->SetTitle("Events/pb");
   METopt37->GetYaxis()->SetLabelFont(42);
   METopt37->GetYaxis()->SetLabelSize(0.035);
   METopt37->GetYaxis()->SetTitleSize(0.035);
   METopt37->GetYaxis()->SetTitleFont(42);
   METopt37->GetZaxis()->SetLabelFont(42);
   METopt37->GetZaxis()->SetLabelSize(0.035);
   METopt37->GetZaxis()->SetTitleSize(0.035);
   METopt37->GetZaxis()->SetTitleFont(42);
   METopt->Add(METopt,"");
   
   TH1D *METopt38 = new TH1D("METopt38","MET/p_{T}^{lead jet}",15,0,3);
   METopt38->SetBinContent(1,5.851509e-06);
   METopt38->SetBinContent(2,0.0002960863);
   METopt38->SetBinContent(3,0.002055587);
   METopt38->SetBinContent(4,0.009485694);
   METopt38->SetBinContent(5,0.02637833);
   METopt38->SetBinContent(6,0.03542185);
   METopt38->SetBinContent(7,0.02902985);
   METopt38->SetBinContent(8,0.01931192);
   METopt38->SetBinContent(9,0.01045294);
   METopt38->SetBinContent(10,0.006260894);
   METopt38->SetBinContent(11,0.004006631);
   METopt38->SetBinContent(12,0.001811275);
   METopt38->SetBinContent(13,0.001055017);
   METopt38->SetBinContent(14,0.0003970447);
   METopt38->SetBinContent(15,0.0002648587);
   METopt38->SetBinContent(16,0.0002425362);
   METopt38->SetBinError(1,2.616874e-06);
   METopt38->SetBinError(2,1.861479e-05);
   METopt38->SetBinError(3,5.431574e-05);
   METopt38->SetBinError(4,0.0002770452);
   METopt38->SetBinError(5,0.000680549);
   METopt38->SetBinError(6,0.0009013724);
   METopt38->SetBinError(7,0.0009115706);
   METopt38->SetBinError(8,0.0007784417);
   METopt38->SetBinError(9,0.0005631055);
   METopt38->SetBinError(10,0.000447395);
   METopt38->SetBinError(11,0.0003988073);
   METopt38->SetBinError(12,0.0002844883);
   METopt38->SetBinError(13,0.0002045993);
   METopt38->SetBinError(14,0.0001303943);
   METopt38->SetBinError(15,8.467851e-05);
   METopt38->SetBinError(16,0.0001139839);
   METopt38->SetEntries(19290);

   ci = TColor::GetColor("#ffcc00");
   METopt38->SetFillColor(ci);

   ci = TColor::GetColor("#ffcc00");
   METopt38->SetLineColor(ci);

   ci = TColor::GetColor("#ffcc00");
   METopt38->SetMarkerColor(ci);
   METopt38->SetMarkerStyle(21);
   METopt38->GetXaxis()->SetTitle("METopt");
   METopt38->GetXaxis()->SetLabelFont(42);
   METopt38->GetXaxis()->SetLabelSize(0.035);
   METopt38->GetXaxis()->SetTitleSize(0.035);
   METopt38->GetXaxis()->SetTitleFont(42);
   METopt38->GetYaxis()->SetTitle("Events/pb");
   METopt38->GetYaxis()->SetLabelFont(42);
   METopt38->GetYaxis()->SetLabelSize(0.035);
   METopt38->GetYaxis()->SetTitleSize(0.035);
   METopt38->GetYaxis()->SetTitleFont(42);
   METopt38->GetZaxis()->SetLabelFont(42);
   METopt38->GetZaxis()->SetLabelSize(0.035);
   METopt38->GetZaxis()->SetTitleSize(0.035);
   METopt38->GetZaxis()->SetTitleFont(42);
   METopt->Add(METopt,"");
   
   TH1D *METopt39 = new TH1D("METopt39","MET/p_{T}^{lead jet}",15,0,3);
   METopt39->SetBinContent(2,1.542458e-05);
   METopt39->SetBinContent(3,9.254746e-05);
   METopt39->SetBinContent(4,0.0009717483);
   METopt39->SetBinContent(5,0.003146613);
   METopt39->SetBinContent(6,0.003840719);
   METopt39->SetBinContent(7,0.002637602);
   METopt39->SetBinContent(8,0.001758402);
   METopt39->SetBinContent(9,0.001326514);
   METopt39->SetBinContent(10,0.0007866534);
   METopt39->SetBinContent(11,0.0004781619);
   METopt39->SetBinContent(12,0.0003084915);
   METopt39->SetBinContent(13,0.0002159441);
   METopt39->SetBinContent(14,0.0001233966);
   METopt39->SetBinContent(15,0.0001233966);
   METopt39->SetBinContent(16,0.000107972);
   METopt39->SetBinError(2,1.542458e-05);
   METopt39->SetBinError(3,3.778234e-05);
   METopt39->SetBinError(4,0.0001224288);
   METopt39->SetBinError(5,0.000220307);
   METopt39->SetBinError(6,0.0002433957);
   METopt39->SetBinError(7,0.0002017025);
   METopt39->SetBinError(8,0.0001646894);
   METopt39->SetBinError(9,0.0001430416);
   METopt39->SetBinError(10,0.0001101535);
   METopt39->SetBinError(11,8.58804e-05);
   METopt39->SetBinError(12,6.89808e-05);
   METopt39->SetBinError(13,5.771348e-05);
   METopt39->SetBinError(14,4.362729e-05);
   METopt39->SetBinError(15,4.362729e-05);
   METopt39->SetBinError(16,4.080959e-05);
   METopt39->SetEntries(1033);

   ci = TColor::GetColor("#ff0000");
   METopt39->SetFillColor(ci);

   ci = TColor::GetColor("#ff0000");
   METopt39->SetLineColor(ci);

   ci = TColor::GetColor("#ff0000");
   METopt39->SetMarkerColor(ci);
   METopt39->SetMarkerStyle(20);
   METopt39->GetXaxis()->SetTitle("METopt");
   METopt39->GetXaxis()->SetLabelFont(42);
   METopt39->GetXaxis()->SetLabelSize(0.035);
   METopt39->GetXaxis()->SetTitleSize(0.035);
   METopt39->GetXaxis()->SetTitleFont(42);
   METopt39->GetYaxis()->SetTitle("Events/pb");
   METopt39->GetYaxis()->SetLabelFont(42);
   METopt39->GetYaxis()->SetLabelSize(0.035);
   METopt39->GetYaxis()->SetTitleSize(0.035);
   METopt39->GetYaxis()->SetTitleFont(42);
   METopt39->GetZaxis()->SetLabelFont(42);
   METopt39->GetZaxis()->SetLabelSize(0.035);
   METopt39->GetZaxis()->SetTitleSize(0.035);
   METopt39->GetZaxis()->SetTitleFont(42);
   METopt->Add(METopt,"");
   
   TH1D *METopt40 = new TH1D("METopt40","MET/p_{T}^{lead jet}",15,0,3);
   METopt40->SetBinContent(4,1.677165e-05);
   METopt40->SetBinError(4,1.677165e-05);
   METopt40->SetEntries(1);

   ci = TColor::GetColor("#0000ff");
   METopt40->SetFillColor(ci);

   ci = TColor::GetColor("#0000ff");
   METopt40->SetLineColor(ci);

   ci = TColor::GetColor("#0000ff");
   METopt40->SetMarkerColor(ci);
   METopt40->SetMarkerStyle(21);
   METopt40->GetXaxis()->SetTitle("METopt");
   METopt40->GetXaxis()->SetLabelFont(42);
   METopt40->GetXaxis()->SetLabelSize(0.035);
   METopt40->GetXaxis()->SetTitleSize(0.035);
   METopt40->GetXaxis()->SetTitleFont(42);
   METopt40->GetYaxis()->SetTitle("Events/pb");
   METopt40->GetYaxis()->SetLabelFont(42);
   METopt40->GetYaxis()->SetLabelSize(0.035);
   METopt40->GetYaxis()->SetTitleSize(0.035);
   METopt40->GetYaxis()->SetTitleFont(42);
   METopt40->GetZaxis()->SetLabelFont(42);
   METopt40->GetZaxis()->SetLabelSize(0.035);
   METopt40->GetZaxis()->SetTitleSize(0.035);
   METopt40->GetZaxis()->SetTitleFont(42);
   METopt->Add(METopt,"");
   METopt->Draw("nostack");
   
   TPaveText *pt = new TPaveText(0.398046,0.9342857,0.601954,0.995,"blNDC");
   pt->SetName("title");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetFillStyle(0);
   pt->SetTextFont(42);
   TText *AText = pt->AddText("METopt");
   pt->Draw();
   
   TLegend *leg = new TLegend(0.54023,0.639881,0.938218,0.924107,NULL,"brNDC");
   leg->SetBorderSize(1);
   leg->SetTextSize(0.034965);
   leg->SetLineColor(1);
   leg->SetLineStyle(1);
   leg->SetLineWidth(1);
   leg->SetFillColor(0);
   leg->SetFillStyle(1001);
   TLegendEntry *entry=leg->AddEntry("METopt","METopt_QCD","lp");

   ci = TColor::GetColor("#00cc00");
   entry->SetLineColor(ci);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);

   ci = TColor::GetColor("#00cc00");
   entry->SetMarkerColor(ci);
   entry->SetMarkerStyle(22);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("METopt","METopt_WJetsToLNu","lp");

   ci = TColor::GetColor("#00ffff");
   entry->SetLineColor(ci);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);

   ci = TColor::GetColor("#00ffff");
   entry->SetMarkerColor(ci);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("METopt","METopt_ZJetsToNuNu","lp");

   ci = TColor::GetColor("#ffcc00");
   entry->SetLineColor(ci);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);

   ci = TColor::GetColor("#ffcc00");
   entry->SetMarkerColor(ci);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("METopt","METopt_signal","lp");

   ci = TColor::GetColor("#ff0000");
   entry->SetLineColor(ci);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);

   ci = TColor::GetColor("#ff0000");
   entry->SetMarkerColor(ci);
   entry->SetMarkerStyle(20);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   entry=leg->AddEntry("METopt","METopt_ttbar","lp");

   ci = TColor::GetColor("#0000ff");
   entry->SetLineColor(ci);
   entry->SetLineStyle(1);
   entry->SetLineWidth(1);

   ci = TColor::GetColor("#0000ff");
   entry->SetMarkerColor(ci);
   entry->SetMarkerStyle(21);
   entry->SetMarkerSize(1);
   entry->SetTextFont(42);
   leg->Draw();
   METopt->Modified();
   METopt->cd();
   METopt->SetSelected(METopt);
}
示例#26
0
文件: fitB0.C 项目: KiSooLee/Bntuple
TF1 *fit(TTree *nt, TTree *ntMC, double ptmin,double ptmax)
{   
   //cout<<cut.Data()<<endl;
   static int count=0;
   count++;
   TCanvas *c= new TCanvas(Form("c%d",count),"",600,600);
   TH1D *h = new TH1D(Form("h%d",count),"",30,5.03,5.93);
//   TH1D *hBck = new TH1D(Form("hBck%d",count),"",40,5,6);
   
   TH1D *hMC = new TH1D(Form("hMC%d",count),"",30,5.03,5.93);
   // Fit function
   //QM2014
   //TString iNP="6.71675e+00*Gaus(x,5.30142e+00,8.42680e-02)/(sqrt(2*3.14159)*8.42680e-02)+4.06744e+01*Gaus(x,5.00954e+00,8.11305e-02)/(sqrt(2*3.14159)*8.11305e-02)+5.99974e-01*(2.376716*Gaus(x,5.640619,0.095530)/(sqrt(2*3.14159)*0.095530)+3.702342*Gaus(x,5.501706,0.046222)/(sqrt(2*3.14159)*0.046222))+1.31767e-01*(61.195688*Gaus(x,5.127566,0.087439)/(sqrt(2*3.14159)*0.087439)+58.943919*Gaus(x,5.246471,0.041983)/(sqrt(2*3.14159)*0.041983))";
   TString iNP="2.28629e1*Gaus(x,5.02606,6.84e-2)/(sqrt(2*3.14159)*(6.84e-2))+3.85695*Gaus(x,5.27701,0.04305)/(sqrt(2*3.14159)*(0.04305))";


   TF1 *f = new TF1(Form("f%d",count),"[0]*([7]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[6]*("+iNP+")");

   nt->Project(Form("h%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax));   
   ntMC->Project(Form("hMC%d",count),"mass",Form("%s&&pt>%f&&pt<%f",seldata_2y_kpi.Data(),ptmin,ptmax));   
//   nt->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax));   
//   nt2->Project(Form("hBck%d",count),"mass",Form("%s&&pt>%f&&pt<%f&&(gen==23333||gen==41000)",seldata.Data(),ptmin,ptmax));   

//   cout <<"nsig = "<<hBck->GetEntries();
   clean0(h);
   h->Draw();
   f->SetParLimits(4,-1000,0);
   f->SetParLimits(2,0.01,0.08);
   f->SetParLimits(8,0.01,0.1);
   f->SetParLimits(7,0,1);
   f->SetParLimits(6,0,1000);

   f->SetParameter(0,setparam0);
   f->SetParameter(1,setparam1);
   f->SetParameter(2,setparam2);
   f->SetParameter(8,setparam3);
   f->FixParameter(1,fixparam1);
   f->FixParameter(6,0);
   h->GetEntries();

   hMC->Fit(Form("f%d",count),"q","",5,6);
   hMC->Fit(Form("f%d",count),"q","",5,6);
   f->ReleaseParameter(1);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L q","",5,6);
   hMC->Fit(Form("f%d",count),"L m","",5,6);

   f->FixParameter(1,f->GetParameter(1));
   f->FixParameter(2,f->GetParameter(2));
   f->FixParameter(7,f->GetParameter(7));
   f->FixParameter(8,f->GetParameter(8));
   f->ReleaseParameter(6);
   
   h->Fit(Form("f%d",count),"q","",5,6);
   h->Fit(Form("f%d",count),"q","",5,6);
   f->ReleaseParameter(1);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L q","",5,6);
   h->Fit(Form("f%d",count),"L m","",5,6);
   h->SetMarkerSize(0.8);
   h->SetMarkerStyle(20);
   cout <<h->GetEntries()<<endl;

   cout<<"======= chi2 ======="<<endl;
   cout<<f->GetChisquare()<<endl;
   cout<<"===== chi2 end ====="<<endl;

   // function for background shape plotting. take the fit result from f
   TF1 *background = new TF1(Form("background%d",count),"[0]+[1]*x");
   background->SetParameter(0,f->GetParameter(3));
   background->SetParameter(1,f->GetParameter(4));
   background->SetLineColor(4);
   background->SetRange(5,6);
   background->SetLineStyle(2);
   
   // function for signal shape plotting. take the fit result from f
   TF1 *Bkpi = new TF1(Form("fBkpi",count),"[0]*("+iNP+")");
   Bkpi->SetParameter(0,f->GetParameter(6));
   Bkpi->SetLineColor(kGreen+1);
   Bkpi->SetFillColor(kGreen+1);
   Bkpi->SetRange(5.00,6.00);
   Bkpi->SetLineStyle(1);
   Bkpi->SetFillStyle(3005);

   // function for signal shape plotting. take the fit result from f
   TF1 *mass = new TF1(Form("fmass",count),"[0]*([3]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[3])*Gaus(x,[1],[4])/(sqrt(2*3.14159)*[4]))");
   mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(8));
   mass->SetParError(0,f->GetParError(0));
   mass->SetParError(1,f->GetParError(1));
   mass->SetParError(2,f->GetParError(2));
   mass->SetParError(7,f->GetParError(7));
   mass->SetParError(8,f->GetParError(8));
   mass->SetLineColor(2);
   mass->SetLineStyle(2);

//   cout <<mass->Integral(0,1.2)<<" "<<mass->IntegralError(0,1.2)<<endl;
   h->SetMarkerStyle(24);
   h->SetStats(0);
   h->Draw("e");
   h->SetXTitle("M_{B} (GeV/c^{2})");
   h->SetYTitle("Entries / (30 MeV/c^{2})");
   h->GetXaxis()->CenterTitle();
   h->GetYaxis()->CenterTitle();
   h->SetTitleOffset(1.5,"Y");
   h->SetAxisRange(0,h->GetMaximum()*1.2,"Y");

 //  hBck->Draw("hist same");

   Bkpi->Draw("same");
   background->Draw("same");   
   mass->SetRange(5,6);
   mass->Draw("same");
   mass->SetLineStyle(2);
   mass->SetFillStyle(3004);
   mass->SetFillColor(2);
   f->Draw("same");

   cout <<"fit result:"<<f->GetParameter(0)*2.5<<" "<<f->Integral(5,6)/h->GetBinWidth(1)<<endl;

   double yield = mass->Integral(5,6)/0.03;
   double yieldErr = mass->Integral(5,6)/0.03*mass->GetParError(0)/mass->GetParameter(0);
   
   // Draw the legend:)   
   TLegend *leg = myLegend(0.50,0.5,0.86,0.89);
   leg->AddEntry(h,"CMS Preliminary","");
   leg->AddEntry(h,"p+Pb #sqrt{s_{NN}}= 5.02 TeV","");
   leg->AddEntry(h,Form("%.0f<p_{T}^{B}<%.0f GeV/c",ptmin,ptmax),"");
   leg->AddEntry(h,"Data","pl");
   leg->AddEntry(f,"Fit","l");
   leg->AddEntry(mass,"Signal","f");
   leg->AddEntry(background,"Combinatorial Background","l");
   leg->AddEntry(Bkpi,"Non-prompt J/#psi","f");
   leg->Draw();
   TLegend *leg2 = myLegend(0.44,0.33,0.89,0.50);
   leg2->AddEntry(h,"B meson","");
   leg2->AddEntry(h,Form("M_{B}=%.2f #pm %.2f MeV/c^{2}",f->GetParameter(1)*1000.,f->GetParError(1)*1000.),"");
   leg2->AddEntry(h,Form("N_{B}=%.0f #pm %.0f",yield,yieldErr),"");
   leg2->Draw();

   //c->SaveAs(Form("../ResultsBzero/BMass-%d.pdf",count));
   c->SaveAs("../../../BzeroDefault.pdf");

   return mass;
}
示例#27
0
//---------------------------------------------------------------------------------------------------
void analyse(const char* directoryName, int chipId)
{
//--- initialize internal data-structures	
  initialize();

//--- read last DAC temperature information used as "training" data
  load(directoryName, chipId);

//--- prepare output graphs

  for ( Int_t itemprange = 0; itemprange < numTempRanges; itemprange++ ){
    TGraph* graph = gADCgraph_Measurement[chipId][itemprange];

    Int_t numPoints = 0;
    for ( Int_t itemperature = 0; itemperature < numTemperatures; itemperature++ ){
      Double_t adcValue   = gADCvalue_Measurement[chipId][itemprange][itemperature];
      Double_t blackLevel = gADCvalue_blackLevel[chipId][itemperature];
//--- only include measurements that correspond to a positive voltage difference
//    (i.e. have an ADC value above the black level)
//    and are within the amplification linear range, below the amplifier saturation
      if ( adcValue > minADCvalue_graph && adcValue < maxADCvalue_graph ){
	graph->SetPoint(numPoints, temperatureValues_target[itemperature], adcValue);
	numPoints++;
      }
    }
  }

  for ( Int_t itemprange = 0; itemprange < numTempRanges; itemprange++ ){
    TGraph* graph = gADCgraph_Calibration[chipId][itemprange];

    Int_t numPoints = 0;
    for ( Int_t itemperature = 0; itemperature < numTemperatures; itemperature++ ){
      Double_t adcValue   = gADCvalue_Calibration[chipId][itemprange][itemperature];
      Double_t blackLevel = gADCvalue_blackLevel[chipId][itemperature];
      //--- only include measurements that correspond to a positive voltage difference
      //    (i.e. have an ADC value above the black level)
      //    and are within the amplification linear range, below the amplifier saturation
      if ( adcValue > minADCvalue_graph && adcValue < maxADCvalue_graph ){
	graph->SetPoint(numPoints, temperatureValues_target[itemperature], adcValue);
	numPoints++;
      }
    }
  }


//--- initialise dummy histogram
//    (neccessary for drawing graphs)
  TH1F* dummyHistogram = new TH1F("dummyHistogram", "dummyHistogram", numTemperatures, temperatureValues_target[0] - 1, temperatureValues_target[numTemperatures - 1] + 1);
  dummyHistogram->SetTitle("");
  dummyHistogram->SetStats(false);
//   dummyHistogram->GetXaxis()->SetTitle("T / degrees");
  dummyHistogram->GetXaxis()->SetTitleOffset(1.2);
//   dummyHistogram->GetYaxis()->SetTitle("ADC");
  dummyHistogram->GetYaxis()->SetTitleOffset(1.3);
  dummyHistogram->SetMaximum(1.25*maxADCvalue_graph);

//--- prepare graph showing range in which the temperature has been measured
//    and the precision of the cooling-box of reaching the temperature setting
    dummyHistogram->GetXaxis()->SetTitle("T/C    ");
    dummyHistogram->GetXaxis()->SetTitleOffset(0.5);
    dummyHistogram->GetXaxis()->SetTitleSize(0.06);
//   dummyHistogram->GetYaxis()->SetTitle("T_{actual} / degrees");
  dummyHistogram->SetMinimum(minADCvalue_graph);
  dummyHistogram->SetMaximum(maxADCvalue_graph);

//--- draw output graphs
  TLegend* legendTempRanges = new TLegend(0.13, 0.47, 0.68, 0.87, NULL, "brNDC");
  legendTempRanges->SetFillColor(10);
  legendTempRanges->SetLineColor(10);

  c1->cd(14);
  //  TString title = Form("ADC Measurement for ROC%i", chipId);
  //  dummyHistogram->SetTitle(title);
  legendTempRanges->Clear();
  Int_t numGraphs = 0;
  for ( Int_t itemprange = 0; itemprange < numTempRanges; itemprange++ ){
    if ( gADCgraph_Measurement[chipId][itemprange]->GetN() >= 2 ){
      if ( numGraphs == 0 ) dummyHistogram->Draw();
      gADCgraph_Measurement[chipId][itemprange]->SetLineColor((itemprange % 8) + 1);
      gADCgraph_Measurement[chipId][itemprange]->SetLineStyle((itemprange / 8) + 1);
      gADCgraph_Measurement[chipId][itemprange]->SetLineWidth(2);
      gADCgraph_Measurement[chipId][itemprange]->Draw("L");
      numGraphs++;
      TString label = Form("Vref = %3.2f", vReference[itemprange]);
      legendTempRanges->AddEntry(gADCgraph_Measurement[chipId][itemprange], label, "l");
    }
  }
   
  tl->DrawLatex(0.12, 0.92, "ADC Measurement"); 
   if ( numGraphs > 0 ){
     legendTempRanges->Draw();
    
//     gCanvas->Update();
//     gPostScript->NewPage();
   }
  
  
  c1->cd(15);
//   TString title = Form("ADC Calibration for ROC%i", chipId);
//   dummyHistogram->SetTitle(title);
  legendTempRanges->Clear();
  Int_t numGraphs = 0;
  for ( Int_t itemprange = 0; itemprange < numTempRanges; itemprange++ ){
    if ( gADCgraph_Calibration[chipId][itemprange]->GetN() >= 2 ){
      if ( numGraphs == 0 ) dummyHistogram->Draw();
      gADCgraph_Calibration[chipId][itemprange]->SetLineColor((itemprange % 8) + 1);
      gADCgraph_Calibration[chipId][itemprange]->SetLineStyle((itemprange / 8) + 1);
      gADCgraph_Calibration[chipId][itemprange]->SetLineWidth(2);
      gADCgraph_Calibration[chipId][itemprange]->Draw("L");
      numGraphs++;
      TString label = Form("Vref = %3.2f", vReference[itemprange]);
      legendTempRanges->AddEntry(gADCgraph_Calibration[chipId][itemprange], label, "l");
    }
  }
 
  tl->DrawLatex(0.12, 0.92, "ADC Calibration");   
   if ( numGraphs > 0 ){
     legendTempRanges->Draw();
    
//     gCanvas->Update();
//     gPostScript->NewPage();
   }
   	
  //  delete gCanvas;
  //  delete gPostScript;
}
示例#28
0
文件: plot.cpp 项目: skhal/bsm_mc
void generatePlots(Files *inputs, const string &path)
{
    Files::const_iterator first_source = inputs->begin();
    TDirectory *folder = dynamic_cast<TDirectory *>(first_source->second->Get(path.c_str()));
    if (!folder)
    {
        cerr << "Failed to extract folder: " << path << endl;

        return;
    }
    //
    //gain time, do not add the objects in the list in memory
    //
    Bool_t status = TH1::AddDirectoryStatus();
    TH1::AddDirectory(kFALSE);

    // loop over all keys in this directory
    TIter nextkey(folder->GetListOfKeys() );

    for(TKey *key, *oldkey=0; key = (TKey*) nextkey(); )
    {
        //keep only the highest cycle number for each key
        if (oldkey
            && !strcmp(oldkey->GetName(), key->GetName()))

            continue;

        // read object from first source file
        //
        TObject *obj = key->ReadObj();

        if ( obj->IsA()->InheritsFrom(TH1::Class()))
        {
            cout << obj->GetName() << endl;

            TCanvas *canvas = new TCanvas();

            canvas->SetWindowSize(640, 480);

            THStack *stack = new THStack();
            TLegend  *legend = new TLegend(.6, .98, .98, .58);
            legend->SetBorderSize(1);
            legend->SetLineStyle(1);
            legend->SetTextFont(43);
            legend->SetTextSizePixels(12);
            legend->SetFillColor(0);

            TH1 *h1 = dynamic_cast<TH1*>(obj);
            legend->AddEntry(h1, style(h1, first_source->first).c_str(), "pl");
            h1->Scale(1.0 / h1->Integral());

            stack->Add(h1);

            // loop over all source files and add the content of the
            // correspondant histogram to the one pointed to by "h1"
            for(Files::const_iterator input = ++inputs->begin();
                    inputs->end() != input;
                    ++input)
            {
                TH1 *h2 = dynamic_cast<TH1*>(input->second->Get((path + "/" + obj->GetName()).c_str()));
                if (!h2)
                {
                    cerr << "Failed to extract plot from input: " << endl;

                    continue;
                }

                h2->Scale(1. / h2->Integral());
                legend->AddEntry(h2, style(h2, input->first).c_str(), "pl");
                stack->Add(h2);
            }

            stack->Draw("h nostack");
            legend->Draw();
            stack->GetXaxis()->SetTitle(h1->GetXaxis()->GetTitle());

            canvas->Update();
        } else {
            // object is of no type that we know or can handle
            //
            cout << "Unknown object type, name: "
                << obj->GetName() << " title: " << obj->GetTitle() << endl;
        }
    }

    // save modifications to target file
    TH1::AddDirectory(status);
}
示例#29
0
int main(int argc, char *argv[])
{
  ApplyLHCbStyle();
  double maxrate;
  switch(argc)
  {
    case 2:
      maxrate=-1;
      break;
    case 3:
      if(atoi(argv[2]))
        maxrate=atoi(argv[2]);
      else
      {
        cout << "Argument not a number" << endl;
        return 1;
      }
      break;
    default:
      cout << "Usage: " << argv[0] << " <Filename> [<Max rate>]" << endl;
      return 1;
  }
  if(system("[ -a figs ]") != 0)
  {
    cout << "Directory ./figs/ does not exist" << endl;
    const int mkdirerr = system("mkdir figs");
    if(mkdirerr != 0)
    {
      cout << "Error code " << mkdirerr << " while creating ./figs/" << endl;
    }
    else
    {
      cout << "Directory ./figs/ created" << endl;
    }
  }
  TFile* file = new TFile(argv[1]);
  if(!file->IsOpen())
  {
    cout << "Exiting" << endl;
    return 1;
  }
  TTree* tree = (TTree*)file->Get("metatree");
  int iHV; tree->SetBranchAddress("HV", &iHV);
  vector<int> HVs;
  string HV;
  int n = tree->GetEntries();
  TCanvas* mapscan, * histcan, * graphcan, * indivgraphcan[4];
  TPad* mapspad[4], * histpad[4];
  TH1D* hist;
  TH2D* map;
  string title[4] = {"JB", "JT", "ST", "SB"};
//  string title[4] = {"FA0026", "DA0024", "FA0019", "FA0006"};
  TGraphErrors* graph[4];
  TMultiGraph* mg;
  TLegend* lg;
  float xlo, xhi, ylo, yhi;
//  rainbowgradient();
  heatmapgradient();
//  DarkBodyRadiator();
//  DarkBodyRadiator2();
//  redbluegradient();
//  heatmapRB();
  string plotname;
  stringstream plotnamestream;
  double* x[4], * y[4], * xe[4], * ye[4];
  for(int j = 0; j < 4; j++)
  {
    x[j]  = new double[n];
    y[j]  = new double[n];
    xe[j] = new double[n];
    ye[j] = new double[n];
  }

  Double_t maxima[4];
  cout << "Entering loop of " << n << " events." << endl;
  for(int i = 0; i < n; i++)
  {
    tree->GetEntry(i);
    HVs.push_back(iHV);
    HV = itoa(iHV);
    for(int j = 0; j < 4; j++)
    {
      map = (TH2D*)file->Get(("DarkMap"+HV+"V"+itoa(j)).c_str());
      maxima[j] = map->GetMaximum();
    }
  }
  sort(HVs.begin(), HVs.end());
  if(maxrate==-1)
  {
    for(int i = 1; i < 4; i++)
    {
      maxrate = TMath::Max(maxima[i-1], maxima[i]);
      maxima[i]=maxrate;
    }
  }
//  cout << "Plotting with a maximum rate of " << maxrate << endl;
  for(int i = 0; i < n; i++)
  {
    HV = itoa(HVs[i]);
    plotnamestream << "DarkRate" << setfill('0') << setw(4) << HVs[i];
    plotnamestream >> plotname;
    histcan = new TCanvas(plotname.c_str(), "", 800, 800);
    plotnamestream.clear();
    histcan->Draw();
    plotnamestream << "DarkMap" << setfill('0') << setw(4) << HVs[i];
    plotnamestream >> plotname;
    mapscan = new TCanvas(plotname.c_str(), "", 800, 800);
    plotnamestream.clear();
    mapscan->Draw();
    for(int j = 0; j < 4; j++)
    {
      // Set limits
      xlo = 0.5*((j/2)%2);
      xhi = xlo+0.5;
      ylo = 0.5*((j+((j/2)%2))%2);
      yhi = ylo+0.5;
      // 2D maps
      mapscan->cd();
      mapspad[j] = new TPad("", "", xlo, ylo, xhi, yhi);
      mapspad[j]->SetLeftMargin(  0.05);
      mapspad[j]->SetRightMargin( 0.15);
      mapspad[j]->SetTopMargin(   0.05);
      mapspad[j]->SetBottomMargin(0.05);
      mapspad[j]->Draw();
      mapspad[j]->cd();
      map = (TH2D*)file->Get(("DarkMap"+HV+"V"+itoa(j)).c_str());
      map->SetTitle("");
      map->SetMaximum(maxrate);
      map->SetMinimum(0);
      map->Draw("COLZ");
      // 1D histogram
      histcan->cd();
      histpad[j] = new TPad("", "", xlo, ylo, xhi, yhi);
      histpad[j]->SetLeftMargin(  0.05);
      histpad[j]->SetRightMargin( 0.15);
      histpad[j]->SetTopMargin(   0.05);
      histpad[j]->SetBottomMargin(0.05);
      histpad[j]->Draw();
      histpad[j]->SetLogy();
      histpad[j]->cd();
      hist = new TH1D(("hist"+itoa(i)+itoa(j)).c_str(), title[j].c_str(), 100, 0, maxrate);
      tree->Draw(("rate"+itoa(j)+">>"+hist->GetName()).c_str(), "", "", 1, i);
      // Graph
      x[j][i]  = HVs[i];
      xe[j][i] = 0;
      y[j][i]  = 0;
      ye[j][i] = 0;
      double yval = 0, yerr = 0;
      double npix = 0;
      for(int k = 0; k < 64; k++)
      {
        yval = map->GetBinContent((k/8)+1, (k%8)+1);
        yerr = map->GetBinError((k/8)+1, (k%8)+1);
        if(yval<0) continue;
        y[j][i]  += yval;
        ye[j][i] += yerr*yerr;
        npix++;
      }
      y[j][i]  /= npix;
      ye[j][i] = sqrt(ye[j][i])/npix;
      cout << npix << "\t" <<  y[j][i] << "±" << ye[j][i] << endl;
    }
    gStyle->SetOptStat("m");
    histcan->SaveAs(("./figs/"+(string)histcan->GetName()+".pdf").c_str());
    histcan->SaveAs(("./figs/"+(string)histcan->GetName()+".png").c_str());
    mapscan->SaveAs(("./figs/"+(string)mapscan->GetName()+".pdf").c_str());
    mapscan->SaveAs(("./figs/"+(string)mapscan->GetName()+".png").c_str());
  }
  mg = new TMultiGraph();
  lg = new TLegend(0.17,0.6,0.45,0.82);
  lg->SetFillStyle(0);
  lg->SetLineWidth(0);
  int linecolour[4] = {kBlue,kRed+1,kGreen+1,kViolet};
  int linestyle[4]  = {2,9,3,5};
  int index[4] = {1, 0, 2, 3}; // More sensible order
  for(int k = 0; k < 4; k++)
  {
    int j = index[k];
    graph[j] = new TGraphErrors(n, x[j], y[j], xe[j], ye[j]);
    graph[j]->SetTitle(title[j].c_str());
    graph[j]->SetLineWidth(2);
    indivgraphcan[j] = new TCanvas((title[j]+"graph").c_str(),"",1000,900);
    indivgraphcan[j]->Draw();
    graph[j]->GetXaxis()->SetTitle("High Voltage [V]");
    graph[j]->GetYaxis()->SetTitle("Dark count rate [Hz]");
    graph[j]->GetYaxis()->SetTitleOffset(1.25);
    graph[j]->SetMinimum(0);
    graph[j]->Draw("APL");
    indivgraphcan[j]->SaveAs(("./figs/graph"+title[j]+".pdf").c_str());
    graph[j]->SetLineColor(linecolour[j]);
    graph[j]->Fit("pol1");
    graph[j]->GetFunction("pol1")->SetLineColor(graph[j]->GetLineColor());
    graph[j]->GetFunction("pol1")->SetLineStyle(linestyle[j]);
    lg->AddEntry(graph[j]->GetFunction("pol1"),title[j].c_str(),"L");
    mg->Add(graph[j], "P");
  }
  graphcan = new TCanvas("graph", "", 900, 900);
  graphcan->cd();
  graphcan->Draw();
  mg->SetMinimum(0);
  mg->Draw("APL");
  mg->GetXaxis()->SetTitle("High Voltage [V]");
  mg->GetYaxis()->SetTitle("Dark count rate [Hz]");
  mg->GetXaxis()->SetTitleOffset(1.2);
  mg->GetYaxis()->SetTitleOffset(1.2);
  GetLHCbName()->Draw();
  lg->Draw();
  graphcan->SaveAs("figs/graph.pdf");

  cout << "\\hline" << endl << "Voltage";
  for(int j = 0; j < 4; j++)
  {
    cout << " & " << title[j];
  }
  cout << "\\\\\\hline" << endl;
  for(int i = 0; i < n; i++)
  {
    cout << HVs[i];
    for(int j = 0; j < 4; j++)
    {
      cout << setprecision(3) << " & " << y[j][i];
    }
    cout << "\\\\\\hline" << endl;
  }
  return 0;
}
void ComparisonPrelim2760GeV(const char *suffix = "eps"){

	TString 	FileDirectory[2];
   TString 	cutNumberAdv[2];
	char* 	Input[256];
	TString 	prefix2;
	Double_t 	nColls[2];

	StyleSettingsThesis();

	SetPlotStyle();

	Bool_t pictDrawingOptions[4] = {kFALSE, kFALSE, kFALSE, kTRUE};

	prefix2 = 			"data";
	pictDrawingOptions[1] = 	kFALSE;
   TString dateForOutput = ReturnDateStringForOutput();
   
	TString collisionSystem = "pp @ 2.76 TeV";
	
	TString FileNameCorrectedCombined[3];
	FileNameCorrectedCombined[0] = "/home/fredi/Photon/Results/ppAnalysis2760GeVFeb2013/CombinedResultsPaperX.root";
	FileNameCorrectedCombined[1] = "/home/fredi/Photon/Results/PbPbAnalysisFinerCentOnlyMinBias/FinalResults/CombinedResultsPaperX_IncludingPP2760YShifted.root";
   FileNameCorrectedCombined[2] = "/home/fredi/Photon/Results/PbPbNewMCTest/CombinedResultsPaperX_19_Sep_2013.root";
	TFile *Cutcorrfile[3];
	TFile *Cutuncorrfile[3];
   TString FileNameCorrectedPCM[3];
   FileNameCorrectedPCM[0] = "/home/fredi/Photon/Results/ppAnalysis2760GeVFeb2013/0000011002093663003800000_01631031009/data_GammaConversionResultsFullCorrectionNoBinShifting.root";
   FileNameCorrectedPCM[1] = "/home/fredi/Photon/Results/PbPbAnalysisFinerCentOnlyMinBias/FinalResults/data_GammaConversionResultsFullCorrection_110521_PreliminaryQM2011.root";
   FileNameCorrectedPCM[2] = "/home/fredi/Photon/Results/PbPbNewMCTest/000001100209366300380000000_01631031009000/data_PCMResultsFullCorrection_PP_NoBinShifting.root";

	TGraphAsymmErrors *finalSpectraComb[3];
	TGraphAsymmErrors *finalSpectraStatErr[3];
	TGraphAsymmErrors *finalSpectraSysErr[3];
	TGraphAsymmErrors *finalSpectraPCMStatErr[3];
	TGraphAsymmErrors *finalSpectraPCMSysErr[3];	
	TGraphAsymmErrors *finalSpectraPHOSStatErr[3];
	TGraphAsymmErrors *finalSpectraPHOSSysErr[3];
	
	TH1D *histoEffi[3];
	TH1D *histoRawYield[3];
	TDirectory *directoryPi02760GeV[3];
	TH1D* histoInvCrossSectionPi02760GeV[3];
	TGraphAsymmErrors* graphInvCrossSectionSysAPi02760GeV[3];
	TFile* CutcorrfilePCM[3];
	
	cout<< FileNameCorrectedCombined[0] << endl;
	Cutcorrfile[0] = new TFile( FileNameCorrectedCombined[0].Data());
	cout << "here" << endl;
	finalSpectraComb[0] = (TGraphAsymmErrors*)Cutcorrfile[0]->Get("graphInvCrossSectionPi0Comb2760GeV");
	cout << "here" << endl;
	finalSpectraStatErr[0] = (TGraphAsymmErrors*)Cutcorrfile[0]->Get("graphInvCrossSectionPi0Comb2760GeVStatErr");
	cout << "here" << endl;
	finalSpectraSysErr[0] = (TGraphAsymmErrors*)Cutcorrfile[0]->Get("graphInvCrossSectionPi0Comb2760GeVSysErr");
	finalSpectraPCMStatErr[0] = (TGraphAsymmErrors*)Cutcorrfile[0]->Get("graphInvCrossSectionPi0PCM2760GeVStatErr");
	cout << "here" << endl;
	finalSpectraPCMSysErr[0] = (TGraphAsymmErrors*)Cutcorrfile[0]->Get("graphInvCrossSectionPi0PCM2760GeVSysErr");
   finalSpectraPCMSysErr[0]->Print();
	finalSpectraPHOSStatErr[0] = (TGraphAsymmErrors*)Cutcorrfile[0]->Get("graphInvCrossSectionPi0PHOS2760GeVStatErr");
	cout << "here" << endl;
	finalSpectraPHOSSysErr[0] = (TGraphAsymmErrors*)Cutcorrfile[0]->Get("graphInvCrossSectionPi0PHOS2760GeVSysErr");
	
   cout << FileNameCorrectedPCM[0] << endl;
   CutcorrfilePCM[0] = new TFile( FileNameCorrectedPCM[0].Data());
   directoryPi02760GeV[0] =         (TDirectory*)CutcorrfilePCM[0]->Get("Pi02.76TeV");    
   histoInvCrossSectionPi02760GeV[0]=        (TH1D*)directoryPi02760GeV[0]->Get("InvCrossSectionPi0");
   graphInvCrossSectionSysAPi02760GeV[0]=       (TGraphAsymmErrors*)directoryPi02760GeV[0]->Get("InvCrossSectionPi0SysA");
   
	cout << "here" << endl;
	cout<<"=========================="<<endl;

	cout<< FileNameCorrectedCombined[1] << endl;
// 	Cutcorrfile[1] = new TFile("/home/fredi/Photon/Results/ppAnalysis2760GeVDec/FinalResults/CombinedResultsPaperX_IncludingPP2760YShifted.root");
// 	finalSpectraComb[1] = (TGraphAsymmErrors*)Cutcorrfile[1]->Get("graphInvCrossSectionPi0Comb2760GeV_PrelimQM2011");
// 	finalSpectraStatErr[1] = (TGraphAsymmErrors*)Cutcorrfile[1]->Get("graphInvCrossSectionPi0Comb2760GeVStatErr_PrelimQM2011");
// 	cout << "here" << endl;
// 	finalSpectraSysErr[1] = (TGraphAsymmErrors*)Cutcorrfile[1]->Get("graphInvCrossSectionPi0Comb2760GeVSysErr_PrelimQM2011");
// 	cout << "here" << endl;
	Cutcorrfile[1] = new TFile(FileNameCorrectedCombined[1].Data());
	finalSpectraComb[1] = (TGraphAsymmErrors*)Cutcorrfile[1]->Get("graphInvCrossSectionPi0Comb2760GeV_PrelimQM2011");
	finalSpectraPCMStatErr[1] = (TGraphAsymmErrors*)Cutcorrfile[1]->Get("graphInvCrossSectionPi0PCMStat2760GeV_PrelimQM2011_YShifted");
	cout << "here" << endl;
	finalSpectraPCMSysErr[1] = (TGraphAsymmErrors*)Cutcorrfile[1]->Get("graphInvCrossSectionPi0PCMSys2760GeV_PrelimQM2011_YShifted");
	finalSpectraPHOSStatErr[1] = (TGraphAsymmErrors*)Cutcorrfile[1]->Get("graphInvCrossSectionPi0PHOSSys2760GeV_PrelimQM2011_YShifted");
	cout << "here" << endl;
	finalSpectraPHOSSysErr[1] = (TGraphAsymmErrors*)Cutcorrfile[1]->Get("graphInvCrossSectionPi0PHOSSys2760GeV_PrelimQM2011_YShifted");
	
   cout << FileNameCorrectedPCM[1] << endl;
   CutcorrfilePCM[1] = new TFile( FileNameCorrectedPCM[1].Data());
   directoryPi02760GeV[1] =         (TDirectory*)CutcorrfilePCM[1]->Get("Pi02.76TeV");    
   histoInvCrossSectionPi02760GeV[1]=        (TH1D*)directoryPi02760GeV[1]->Get("InvCrossSectionPi0");
   graphInvCrossSectionSysAPi02760GeV[1]=       (TGraphAsymmErrors*)directoryPi02760GeV[1]->Get("InvCrossSectionPi0SysA");

	cout<<"=========================="<<endl;

   cout<< FileNameCorrectedCombined[2] << endl;
   Cutcorrfile[2] = new TFile( FileNameCorrectedCombined[2].Data());
   cout << "here" << endl;
   finalSpectraComb[2] = (TGraphAsymmErrors*)Cutcorrfile[2]->Get("graphInvCrossSectionPi0Comb2760GeV");
   cout << "here" << endl;
   finalSpectraStatErr[2] = (TGraphAsymmErrors*)Cutcorrfile[2]->Get("graphInvCrossSectionPi0Comb2760GeVStatErr");
   cout << "here" << endl;
   finalSpectraSysErr[2] = (TGraphAsymmErrors*)Cutcorrfile[2]->Get("graphInvCrossSectionPi0Comb2760GeVSysErr");
   finalSpectraPCMStatErr[2] = (TGraphAsymmErrors*)Cutcorrfile[2]->Get("graphInvCrossSectionPi0PCM2760GeVStatErr");
   cout << "here" << endl;
   finalSpectraPCMSysErr[2] = (TGraphAsymmErrors*)Cutcorrfile[2]->Get("graphInvCrossSectionPi0PCM2760GeVSysErr");
   finalSpectraPCMSysErr[2]->Print();
   finalSpectraPHOSStatErr[2] = (TGraphAsymmErrors*)Cutcorrfile[2]->Get("graphInvCrossSectionPi0PHOS2760GeVStatErr");
   cout << "here" << endl;
   finalSpectraPHOSSysErr[2] = (TGraphAsymmErrors*)Cutcorrfile[2]->Get("graphInvCrossSectionPi0PHOS2760GeVSysErr");

   cout << FileNameCorrectedPCM[2] << endl;
   CutcorrfilePCM[2] = new TFile( FileNameCorrectedPCM[2].Data());
   directoryPi02760GeV[2] =         (TDirectory*)CutcorrfilePCM[2]->Get("Pi02.76TeV");    
   histoInvCrossSectionPi02760GeV[2]=        (TH1D*)directoryPi02760GeV[2]->Get("InvCrossSectionPi0");
   graphInvCrossSectionSysAPi02760GeV[2]=       (TGraphAsymmErrors*)directoryPi02760GeV[2]->Get("InvCrossSectionPi0SysA");

   cout << "here" << endl;
   cout<<"=========================="<<endl;

   
	Double_t paramGraph[3] = {1.0e12,7.,0.13};
	TF1*	fitInvCrossSectionPi02760GeV = FitObject("l","fitInvCrossSectionPi02760GeV","Pi0",finalSpectraComb[1],0.4,12.,paramGraph);
	cout << WriteParameterToFile(fitInvCrossSectionPi02760GeV)<< endl;

	TGraphAsymmErrors *graphRatioFinalToPrelimStat = CalculateGraphErrRatioToFit (finalSpectraStatErr[2], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalToPrelimSys = CalculateGraphErrRatioToFit (finalSpectraSysErr[2], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalPCMToPrelimStat = CalculateGraphErrRatioToFit (finalSpectraPCMStatErr[2], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalPCMToPrelimSys = CalculateGraphErrRatioToFit (finalSpectraPCMSysErr[2], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalPHOSToPrelimStat = CalculateGraphErrRatioToFit (finalSpectraPHOSStatErr[2], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalPHOSToPrelimSys = CalculateGraphErrRatioToFit (finalSpectraPHOSSysErr[2], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalPCMPrelimToPrelimStat = CalculateGraphErrRatioToFit (finalSpectraPCMStatErr[1], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalPCMPrelimToPrelimSys = CalculateGraphErrRatioToFit (finalSpectraPCMSysErr[1], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalPHOSPrelimToPrelimStat = CalculateGraphErrRatioToFit (finalSpectraPHOSStatErr[1], fitInvCrossSectionPi02760GeV); 
	TGraphAsymmErrors *graphRatioFinalPHOSPrelimToPrelimSys = CalculateGraphErrRatioToFit (finalSpectraPHOSSysErr[1], fitInvCrossSectionPi02760GeV); 
	
   TGraphAsymmErrors* graphRatioFinalUpdatedPCMToFinalSys = CalculateGraphAsymErrRatioToGraphErr (finalSpectraStatErr[2],finalSpectraStatErr[0],kTRUE);
   TH1D* histoRatioFinalUpdatedPCMToFinalStat = (TH1D*)histoInvCrossSectionPi02760GeV[2]->Clone("histoRatioFinalUpdatedPCMToFinalStat");
   histoRatioFinalUpdatedPCMToFinalStat->Divide(histoRatioFinalUpdatedPCMToFinalStat,histoInvCrossSectionPi02760GeV[0],1.,1.,"B");
   
	//**************************************************************************************
	//********************* Plotting RAW-Yield *********************************************
	//**************************************************************************************

	TCanvas* canvasFraction = new TCanvas("canvasFraction","",1550,1200);  // gives the page size
	canvasFraction->SetTickx();
	canvasFraction->SetTicky();
	canvasFraction->SetGridx(0);
	canvasFraction->SetGridy(0);
	canvasFraction->SetLogy(0);
	canvasFraction->SetLogx(1);
	canvasFraction->SetLeftMargin(0.09);
	canvasFraction->SetRightMargin(0.02);
	canvasFraction->SetTopMargin(0.02);
	canvasFraction->SetFillColor(0);

	TH2F * ratio2DInvXSectionOnlyPi0;
	ratio2DInvXSectionOnlyPi0 = new TH2F("ratio2DInvXSectionOnlyPi0","ratio2DInvXSectionOnlyPi0",1000,0.33,15.,1000,0.5,2.1);
	SetStyleHistoTH2ForGraphs(ratio2DInvXSectionOnlyPi0, "p_{T} (GeV/c)","Final/Fit to Prelim", 0.03,0.042, 0.03,0.042, 0.9,0.82, 512, 505);
// 	ratio2DInvXSectionOnlyPi0->GetXaxis()->SetLabelOffset(-0.015);
// 	ratio2DInvXSectionOnlyPi0->GetYaxis()->SetLabelOffset(0.01);
	ratio2DInvXSectionOnlyPi0->DrawCopy(); 
	
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalToPrelimSys, 20,1.5, kBlue+2 , kBlue+2, 1., kTRUE);
	graphRatioFinalToPrelimSys->Draw("E2same");
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalPCMToPrelimSys, 20,1.5, kBlack , kBlack, 1., kTRUE);
	graphRatioFinalPCMToPrelimSys->Draw("E2same");
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalPHOSToPrelimSys, 20,1.5, kRed+2 , kRed+2, 1., kTRUE);
	graphRatioFinalPHOSToPrelimSys->Draw("E2same");
	
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalToPrelimStat, 20,2., kBlue+2 , kBlue+2);
 	graphRatioFinalToPrelimStat->Draw("p,same,e1");
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalPCMToPrelimStat, 20,2., kBlack , kBlack);
 	graphRatioFinalPCMToPrelimStat->Draw("p,same,e1");
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalPHOSToPrelimStat, 20,2., kRed+2 , kRed+2);
 	graphRatioFinalPHOSToPrelimStat->Draw("p,same,e1");

	TLegend* legendPrelim = new TLegend(0.18,0.83,0.4,0.95);
		legendPrelim->SetFillColor(0);
		legendPrelim->SetLineColor(0);
// 		legendPrelim->SetNColumns(2);
		legendPrelim->SetTextSize(0.045);
		legendPrelim->AddEntry(graphRatioFinalToPrelimSys,"#pi^{0} combined/ fit to combined prelim #pi^{0}","p");
		legendPrelim->AddEntry(graphRatioFinalPCMToPrelimSys,"#pi^{0} PCM/ fit to combined prelim #pi^{0}","p");
		legendPrelim->AddEntry(graphRatioFinalPHOSToPrelimSys,"#pi^{0} PHOS/ fit to combined prelim #pi^{0}","p");
		legendPrelim->Draw();

		legendPrelim->Draw();
	
	canvasFraction->Update();
	DrawGammaLines(0., 15.,1., 1.,0.1);

	canvasFraction->SaveAs(Form("Pi0_Ratio2760GeVFinalDivPrelim_%s.%s",dateForOutput.Data(),suffix));


	canvasFraction->cd();
	ratio2DInvXSectionOnlyPi0->DrawCopy(); 
	
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalPCMPrelimToPrelimSys, 20,1.5, kBlack , kBlack, 1., kTRUE);
	graphRatioFinalPCMPrelimToPrelimSys->Draw("E2same");
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalPHOSPrelimToPrelimSys, 20,1.5, kRed+2 , kRed+2, 1., kTRUE);
	graphRatioFinalPHOSPrelimToPrelimSys->Draw("E2same");
	
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalPCMPrelimToPrelimStat, 20,2., kBlack , kBlack);
 	graphRatioFinalPCMPrelimToPrelimStat->Draw("p,same,e1");
	DrawGammaSetMarkerTGraphAsym(graphRatioFinalPHOSPrelimToPrelimStat, 20,2., kRed+2 , kRed+2);
 	graphRatioFinalPHOSPrelimToPrelimStat->Draw("p,same,e1");

	TLegend* legendPi0PrelimQM2011 = new TLegend(0.18,0.83,0.4,0.95);
		legendPi0PrelimQM2011->SetFillColor(0);
		legendPi0PrelimQM2011->SetLineColor(0);
// 		legendPi0PrelimQM2011->SetNColumns(2);
		legendPi0PrelimQM2011->SetTextSize(0.045);
		legendPi0PrelimQM2011->AddEntry(graphRatioFinalPCMToPrelimSys,"#pi^{0} PCM prelim/ fit to combined prelim #pi^{0}","p");
		legendPi0PrelimQM2011->AddEntry(graphRatioFinalPHOSToPrelimSys,"#pi^{0} PHOS prelim / fit to combined prelim #pi^{0}","p");
		legendPi0PrelimQM2011->Draw();

		legendPi0PrelimQM2011->Draw();
	
	canvasFraction->Update();
	DrawGammaLines(0., 15.,1., 1.,0.1);

	canvasFraction->SaveAs(Form("Pi0_Ratio2760GeVPrelimDivPrelim.%s",suffix));
   
   
   canvasFraction->cd();
   TH2F * ratio2DInvXSectionOnlyPi02;
   ratio2DInvXSectionOnlyPi02 = new TH2F("ratio2DInvXSectionOnlyPi02","ratio2DInvXSectionOnlyPi02",1000,0.33,15.,1000,0.5,2.1);
   SetStyleHistoTH2ForGraphs(ratio2DInvXSectionOnlyPi02, "p_{T} (GeV/c)","Final/Prelim", 0.03,0.042, 0.03,0.042, 0.9,0.82, 512, 505);
//    ratio2DInvXSectionOnlyPi0->GetXaxis()->SetLabelOffset(-0.015);
//    ratio2DInvXSectionOnlyPi0->GetYaxis()->SetLabelOffset(0.01);
   ratio2DInvXSectionOnlyPi02->DrawCopy(); 
   
    TH1D* histoRatioPCM_FinalOverPrelimStat = (TH1D*)histoInvCrossSectionPi02760GeV[1]->Clone("histoRatioPCM_FinalOverPrelimStat");
//    histoRatioPCM_FinalOverPrelimStat->Divide(histoRatioPCM_FinalOverPrelimStat,histoInvCrossSectionPi02760GeV[1],1.,1.,"B");
//    
   for (Int_t i = 2; i < histoInvCrossSectionPi02760GeV[1]->GetNbinsX()+1; i++){
     cout <<  i << "\t" << histoInvCrossSectionPi02760GeV[1]->GetBinCenter(i)-histoInvCrossSectionPi02760GeV[1]->GetBinWidth(i)/2 << endl;
     histoRatioPCM_FinalOverPrelimStat->SetBinContent(i,histoInvCrossSectionPi02760GeV[2]->GetBinContent(i)/histoInvCrossSectionPi02760GeV[1]->GetBinContent(i));
     Double_t error =  TMath::Sqrt( pow(histoInvCrossSectionPi02760GeV[2]->GetBinError(i)/histoInvCrossSectionPi02760GeV[1]->GetBinContent(i),2)  + pow( histoInvCrossSectionPi02760GeV[1]->GetBinError(i)*histoInvCrossSectionPi02760GeV[2]->GetBinContent(i)/pow(histoInvCrossSectionPi02760GeV[1]->GetBinContent(i),2),2) );
     histoRatioPCM_FinalOverPrelimStat->SetBinError(i,error);
     cout <<  i << "\t" << histoRatioPCM_FinalOverPrelimStat->GetBinContent(i) << "\t +- " << histoRatioPCM_FinalOverPrelimStat->GetBinError(i) << endl;
   }
   for (Int_t i = 1; i < histoInvCrossSectionPi02760GeV[2]->GetNbinsX()+1; i++){
     cout <<  i << "\t" << histoInvCrossSectionPi02760GeV[2]->GetBinCenter(i)-histoInvCrossSectionPi02760GeV[2]->GetBinWidth(i)/2 << endl;
   }
   
   
   TGraphAsymmErrors *graphRatioPCM_FinalOverPrelimSys = CalculateGraphAsymErrRatioToGraphErr (graphInvCrossSectionSysAPi02760GeV[2], graphInvCrossSectionSysAPi02760GeV[1]);
   
   DrawGammaSetMarkerTGraphAsym(graphRatioPCM_FinalOverPrelimSys, 20,1.5, kBlack , kBlack, 1., kTRUE);
   graphRatioPCM_FinalOverPrelimSys->Draw("E2same");
  
   DrawGammaSetMarker(histoRatioPCM_FinalOverPrelimStat, 20,2., kBlack , kBlack);
   histoRatioPCM_FinalOverPrelimStat->Draw("p,same,e1");
   
   TLatex *labelPi0PCM = new TLatex(0.15,0.93,"PCM current/ PCM preliminary, removed mat. error from systematics");
   SetStyleTLatex( labelPi0PCM, 0.036,4);
   labelPi0PCM->Draw();
   TLatex *labelPi0PCM2 = new TLatex(0.15,0.89,"Material error old: +8.3%, -4.8%");
   SetStyleTLatex( labelPi0PCM2, 0.036,4);
   labelPi0PCM2->Draw();
   TLatex *labelPi0PCM3 = new TLatex(0.15,0.85,"Material error new: #pm 9.0%");
   SetStyleTLatex( labelPi0PCM3, 0.036,4);
   labelPi0PCM3->Draw();

   canvasFraction->Update();
   DrawGammaLines(0., 15.,1., 1.,0.1);

   canvasFraction->SaveAs(Form("Pi0_Ratio2760GeVFinalDivPrelimPCMPoints_%s.%s",dateForOutput.Data(),suffix));
   
   canvasFraction->cd();
   ratio2DInvXSectionOnlyPi0->GetYaxis()->SetTitle("Final/FinalUpdatedStat");
   ratio2DInvXSectionOnlyPi0->GetYaxis()->SetRangeUser(0.9,1.1);
   ratio2DInvXSectionOnlyPi0->DrawCopy(); 
   
   /*DrawGammaSetMarkerTGraphAsym(graphRatioFinalUpdatedPCMToFinalStat, 20,1.5, kBlack , kBlack, 1., kTRUE);
   graphRatioFinalUpdatedPCMToFinalStat->Draw("Epsame");
   */
   DrawGammaSetMarker(histoRatioFinalUpdatedPCMToFinalStat, 20,1., kBlue , kBlue);
   histoRatioFinalUpdatedPCMToFinalStat->Draw("E1psame");
   canvasFraction->Update();
   DrawGammaLines(0., 15.,1., 1.,0.1);

   canvasFraction->SaveAs(Form("Pi0_Ratio2760GeVFinalDivFinalUpdatedStat_%s.%s",dateForOutput.Data(),suffix));   
	delete canvasFraction;
   
   

}