示例#1
0
文件: covertQuan.C 项目: XuQiao/HI
void covertQuan(){
    TFile *fin = TFile::Open("pPb.root");
//    TFile *fout = new TFile("pPb_xq.root","Recreate");
    int mult[4] = {120,150,185,220};
    int n[4] = {2,4,6,8};
    for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
        TGraphErrors *g = (TGraphErrors*)fin->Get(Form("v2Pt_%d_%d",n[j],mult[i]));
        if(n[j]==4){
        cout<<mult[i]<<endl;
        for(int ibin=0;ibin<g->GetN();ibin++){
            cout<<g->GetX()[ibin]<<",";
        }
        cout<<endl;
        for(int ibin=0;ibin<g->GetN();ibin++){
            cout<<g->GetY()[ibin]<<",";
        }
        cout<<endl;
        for(int ibin=0;ibin<g->GetN();ibin++){
            cout<<g->GetEY()[ibin]<<",";
        }
        cout<<endl;
        }
       // fout->cd();
       // g->Write("AP");
       // g1->Write();
    }
    }
}
示例#2
0
void points(TString filename) {

	
	TString cmssw;
	// 167
	
	cmssw = "$1.6.7$";
	
	TFile *f = TFile::Open(filename);

	std::vector< TString > taggers;
	taggers.push_back( "gTC2_udsg" );
	taggers.push_back( "gTC3_udsg" );
	taggers.push_back( "gTP_udsg" );
	taggers.push_back( "gJBP_udsg" );
 	taggers.push_back( "gSSV_udsg" );
 	taggers.push_back( "gCSV_udsg" );

	std::vector< TString > discriminators;
	discriminators.push_back( "discTC2_udsg" );
	discriminators.push_back( "discTC3_udsg" );
	discriminators.push_back( "discTP_udsg" );
	discriminators.push_back( "discJBP_udsg" );
 	discriminators.push_back( "discSSV_udsg" );
 	discriminators.push_back( "discCSV_udsg" );

	//TCanvas *cv_TC = new TCanvas("cv_TC","cv_TC",700,700);
	//TCanvas *cv_TP = new TCanvas("cv_TP","cv_TP",700,700);

	std::cout << "Tagger & Point & Discriminator & light mistag & b-efficiency \\\\ \\hline" << std::endl;
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {

		TString tag = taggers[itagger];
		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("Histograms/MCtruth/"+tag);

		//if (taggers == "gTC2_udsg" || taggers =
		
		TGraph *dgraph = (TGraph*) gDirectory->Get("Histograms/MCtruth/"+discriminators[itagger]);
		dgraph->Sort();

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		
		//cv[itagger] = new TCanvas("cv","cv",600,600);
		//g->Draw("ACP");
		TString se = " & ";
		
		
		std::cout << tag << se << "Loose" << se << std::setprecision(3) << dgraph->Eval(0.1) << se << "0.1" << se << std::setprecision(2) << g->Eval(0.1) << "\\\\" << std::endl;
		std::cout << tag << se << "Medium" << se << std::setprecision(3) << dgraph->Eval(0.01) << se << "0.01" << se << std::setprecision(2) << g->Eval(0.01) << "\\\\" << std::endl;
		std::cout << tag << se << "Tight" << se << std::setprecision(3) << dgraph->Eval(0.001) << se << "0.001" << se << std::setprecision(2) << g->Eval(0.001) << "\\\\ \\hline" << std::endl;
		
	}

	
}
示例#3
0
printgraph(const char* file, const char* graphname, const char* graphname_syst, bool reverseta=false, double scale=1./34.62)
{
   TFile * f = new TFile(file);
   TGraphErrors *gr = (TGraphErrors*) f->Get(graphname);
   TGraphErrors *grsyst = (TGraphErrors*) f->Get(graphname_syst);

   int nbins = gr->GetN();
   double *x = new double[nbins];
   if (reverseta)
      for (int i=0; i<nbins; i++)
         x[i] = gr->GetX()[nbins-i-1];
   else 
      x = gr->GetX();

   double *y = gr->GetY();
   double *ey = gr->GetEY();
   double *ey_syst = grsyst->GetEY();

   for (int i=0; i<nbins; i++)
      cout << x[i] << ": " << y[i]*scale << "+-" << ey[i]*scale << "(stat.) +-" << ey_syst[i]*scale << "(syst.)" << endl;
}
示例#4
0
void pointsed(TString filename = "btagpatanalyzerpy.root", TString check="") {
	TString cmssw;
	// 167
	
	cmssw = "$3.1.0_pre9$";
	
	TFile *f = TFile::Open(filename);
/////////////////////////////////////////////////////////////////////////////////////////
	std::vector< TString > checks;
	checks.push_back("");
	checks.push_back("Corr30_");
	checks.push_back("Corr30t0_");
	checks.push_back("Corr30t1_");
	checks.push_back("Corr30t2_");
	checks.push_back("Corr30t0_nConstituent_");
	checks.push_back("Corr30t1_nConstituent_");
	checks.push_back("Corr30t2_nConstituent_");
	checks.push_back("Uncor10_");
	checks.push_back("Uncor10t0_");
	checks.push_back("Uncor10t1_");
	checks.push_back("Uncor10t2_");
	checks.push_back("Uncor10t0_nConstituent_");
	checks.push_back("Uncor10t1_nConstituent_");
	checks.push_back("Uncor10t2_nConstituent_");
/////////////////////////////////////////////////////////////////////////////////////////
	std::vector< TString > taggers;
	std::vector< TString > labeltag;
        std::vector< int> colorlines;
	taggers.push_back( "TC2" );colorlines.push_back( 1 );labeltag.push_back( "TCHE");
	taggers.push_back( "TC3" );colorlines.push_back( 2 );labeltag.push_back( "TCHP");
	taggers.push_back( "TP"  );colorlines.push_back( 3 );labeltag.push_back( "JP");
	taggers.push_back( "SSV" );colorlines.push_back( 4 );labeltag.push_back( "SSV");
	taggers.push_back( "CSV" );colorlines.push_back( 5 );labeltag.push_back( "CSV");
	taggers.push_back( "MSV" );colorlines.push_back( 6 );labeltag.push_back( "CSVMVAB");
	taggers.push_back( "SMT" );colorlines.push_back( 8 );labeltag.push_back( "SMT");
	taggers.push_back( "BTP" );colorlines.push_back( 9 );labeltag.push_back( "JBP");
	taggers.push_back( "SMTbyIP3d" );colorlines.push_back( 11 );labeltag.push_back( "SMTByIP3d");
	taggers.push_back( "SMTbyPt" );colorlines.push_back( 12 );labeltag.push_back( "SMTByPt");
	taggers.push_back( "SETbyIP3d" );colorlines.push_back( 13 );labeltag.push_back( "SETByIP3d");
	taggers.push_back( "SETbyPt" );colorlines.push_back( 14 );labeltag.push_back( "SETByPt");
//	taggers.push_back( "IPM" );colorlines.push_back( 11 );labeltag.push_back( "IPMVAB");
//	taggers.push_back( "SMNIPT" );colorlines.push_back( 12 );labeltag.push_back( "SMTNoIP");

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
//ed	for ( size_t ichks = 0; ichks < checks.size(); ++ichks ) {
//ed		TString check = checks[ichks];
	
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
        TString PerfTitle= check;
        if (check == "") PerfTitle="uncorr pt>30";
	if (check == "Corr30_") PerfTitle="pt>30";
	if (check == "Corr30t0_") PerfTitle="pt>30, #tracks > 0";
	if (check == "Corr30t1_") PerfTitle="pt>30, #tracks > 1";
	if (check == "Corr30t2_") PerfTitle="pt>30, #tracks > 2";
	if (check == "Corr30t0_nConstituent_") PerfTitle="pt>30, #tracks > 0 & nConstituents >1";
	if (check == "Corr30t1_nConstituent_") PerfTitle="pt>30, #tracks > 1 & nConstituents >1";
	if (check == "Corr30t2_nConstituent_") PerfTitle="pt>30, #tracks > 2 & nConstituents >1";
	if (check == "Uncor10_") PerfTitle="uncorr pt>10";
	if (check == "Uncor10t0_") PerfTitle="uncorr pt>10 #tracks > 0";
	if (check == "Uncor10t1_") PerfTitle="uncorr pt>10 #tracks > 1";
	if (check == "Uncor10t2_") PerfTitle="uncorr pt>10 #tracks > 2";
	if (check == "Uncor10t0_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 0 & nConstituents >1";
	if (check == "Uncor10t1_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 1 & nConstituents >1";
	if (check == "Uncor10t2_nConstituent_") PerfTitle="uncorr pt>10 #tracks > 2 & nConstituents >1";

	std::vector< TString > discriminators;
        for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
  		discriminators.push_back( check+"disc"+taggers[itagger]+"_udsg" );
	}
//	discriminators.push_back( "discTC3_udsg" );
//	discriminators.push_back( "discTP_udsg" );

	TCanvas *cv = new TCanvas("cv","cv",900,900);
	TMultiGraph *mg =new TMultiGraph();
	TLegend *legend0 = new TLegend(0.68,0.12,0.88,0.32);
        // inverted axis
	TMultiGraph *mginv =new TMultiGraph();
	TLegend *legend1 = new TLegend(0.65,0.18,0.85,0.48);
	std::ofstream salida("BTagPATop3"+check+".txt");
	
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {

		TString tag    = check+"g"+taggers[itagger]+"_udsg";
		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tag);

		
		TGraph *dgraph = (TGraph*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+discriminators[itagger]);
//		TGraph *udsgvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),dgraph->GetX());
		dgraph->Sort();
//		udsgvsdgraph->Sort();

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		g->SetLineColor(itagger+1);
                legend0 -> AddEntry(g,taggers[itagger],"l");
		mg->Add(g);

                //inverted axis
		TGraphErrors *ginv = new TGraphErrors(agraph->GetN(),agraph->GetX(),agraph->GetY(),agraph->GetEX(),agraph->GetEY());
		ginv->Sort();
		ginv->SetLineColor(colorlines[itagger]);
		ginv->SetMarkerStyle(8);
		ginv->SetMarkerColor(colorlines[itagger]);
                legend1 -> AddEntry(ginv,labeltag[itagger],"l");
		mginv->Add(ginv);

		std::cout << " Tagger: " << tag << std::endl;
		std::cout << " Loose(10%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.1) << " b-eff = " << g->Eval(0.1) << std::endl;
		std::cout << " Medium(1%):  " << " cut > " << std::setprecision(4) << dgraph->Eval(0.01) << " b-eff = " << g->Eval(0.01) << std::endl;
		std::cout << " Tight(0.1%) = " << " cut > " << std::setprecision(4) << dgraph->Eval(0.001) << " b-eff = " << g->Eval(0.001) << std::endl;
                salida << " " << taggers[itagger] << endl;
	        salida << " #bin \t b-eff  \t err-beff \t  non-beff \t err-non-b"<< endl;
        	for ( size_t i=0;i< agraph->GetN();i++){ 
			salida	<< "  " << (i+1) << " \t "
				<< agraph->GetX()[i] <<" \t " 
				<< agraph->GetEX()[i]<<" \t "
				<< agraph->GetY()[i] <<" \t "
				<< agraph->GetEY()[i]
                       		<< " "<< endl;
		}

	}
//	cv->SetLogx();
	mg->Draw("ALP");
	mg->GetYaxis()->SetTitle("b-eff");
	mg->GetXaxis()->SetTitle("udsg-mistagging");
	legend0 -> Draw();
        cv-> SetGrid();
	cv-> Print ("BTagPATop"+check+".eps");
	cv-> Print ("BTagPATop"+check+".png");
	cv->cd(0);
	cv->SetLogx();
	mg->Draw("ALP");
	legend0 -> Draw();
	cv-> Print ("BTagPATop1"+check+".eps");
	cv-> Print ("BTagPATop1"+check+".png");
        //inverted axis
	TCanvas *cvinv = new TCanvas("cvinv","cvinv",700,700);
        cvinv->SetLogy(0);
	mginv->Draw("ALP");
	mginv->GetXaxis()->SetTitle("b-eff");
	mginv->GetYaxis()->SetTitle("udsg-mistagging");
	legend1 -> Draw();
        cvinv->SetGrid();
	cvinv-> Print ("BTagPATop2"+check+".eps");
	cvinv-> Print ("BTagPATop2"+check+".png");
	cvinv->cd(0);
//	cvinv->Update();
//	cvinv->SetLogx();
//	mginv->SetXmin(10^-4);
//      axis range using a histogram helper
    TH2D*hpx = new TH2D("hpx",PerfTitle,200,0.0,1.005,200,0.00002,1.05);
        hpx->SetStats(kFALSE);
		hpx->Draw();
	hpx->GetXaxis()->SetTitle("b-eff");
	hpx->GetYaxis()->SetTitle("udsg-mistagging");
	cvinv->SetLogy(1);
	mginv->Draw("AP");
	legend1 -> Draw();
	cvinv-> Print ("BTagPATop3"+check+".eps");
	cvinv-> Print ("BTagPATop3"+check+".png");
	//ed}
}
示例#5
0
void DrawVelocity() {
  gStyle->SetOptFit(11111111);

  TFile* tfCosmic = new TFile("CosmicOut_V4.root");
  TTree* trCosmic = (TTree*)tfCosmic->Get("trOut");
  
  Double_t FitP1[2];
  Double_t FitP0[2];
  Double_t FitChisq[2];
  Int_t    CosmicTrigUp;
  Int_t    CosmicTrigDn;
  Double_t Theta;
  Double_t Roh;

  trCosmic->SetBranchAddress("FitP1"       ,FitP1 );
  trCosmic->SetBranchAddress("FitP0"       ,FitP0 );
  trCosmic->SetBranchAddress("FitChisq"    ,FitChisq);
  trCosmic->SetBranchAddress("CosmicTrigUp",&CosmicTrigUp);
  trCosmic->SetBranchAddress("CosmicTrigDn",&CosmicTrigDn);
  trCosmic->SetBranchAddress("Theta"       ,&Theta);
  trCosmic->SetBranchAddress("Roh"         ,&Roh);
  
  std::cout<< "Output" << std::endl;
  //TFile* tfHist = new TFile("CosmicOut_V4_TrigHist.root","recreate");
  TH1D* CosmicP1UpTrig[5];
  TH1D* CosmicP1Trig[5][5];
  TH1D* CosmicP1TrigLarge[5][5];

  for( int i = 0; i< 5; i++){
    CosmicP1UpTrig[i] = new TH1D( Form("CosmicP1UpTrig%d",i),
				  Form("CosmicP1UpTrig%d",i),
				  100,-0.01,0.01);
    for( int j = 0; j< 5; j++){
      CosmicP1Trig[i][j] = new TH1D( Form("CosmicP1_%d_%d",i,j),
				     Form("CosmicP1_%d_%d",i,j),
				     100,-0.01,0.01);
      CosmicP1TrigLarge[i][j] = new TH1D( Form("CosmicP1Large_%d_%d",i,j),
					  Form("CosmicP1Large_%d_%d",i,j),
					  100,-0.01,0.01);
    }
  }

  std::cout<< "LOOP" << std::endl;
  for( int ievent  = 0; ievent < trCosmic->GetEntries(); ievent++){
    trCosmic->GetEntry(ievent);
    if( TMath::Abs(Theta) < 5 ){ continue; }
    if( FitChisq[1] > 10 ){ continue; }
    CosmicP1UpTrig[ CosmicTrigUp ]->Fill( FitP1[1]*TMath::Cos(Theta*TMath::Pi()/180.));
    CosmicP1Trig[CosmicTrigUp][CosmicTrigDn]->Fill( FitP1[1]*TMath::Cos(Theta*TMath::Pi()/180.) );
    if( Roh > 600){
      CosmicP1TrigLarge[CosmicTrigUp][CosmicTrigDn]->Fill( FitP1[1]*TMath::Cos(Theta*TMath::Pi()/180.) );
    }
  }

  std::cout <<  "Draw" << std::endl;
  TGraphErrors* grSlope = new TGraphErrors();
  TGraphErrors* grDelta = new TGraphErrors();
  TGraphErrors* grSlopeLarge = new TGraphErrors();
  grSlope->SetMarkerStyle( 7 );
  grDelta->SetMarkerStyle( 7 );
  grSlopeLarge->SetMarkerStyle( 7 );
  TCanvas* can = new TCanvas("can","",1200,800);
  can->Divide(3,2);

  for( int i = 0; i< 5; i++){
    for( int j = 0; j< 5; j++){
      CosmicP1Trig[i][j]->Fit("gaus","Q","",
			      CosmicP1Trig[i][j]->GetMean()-CosmicP1Trig[i][j]->GetRMS(), 
			      CosmicP1Trig[i][j]->GetMean()+CosmicP1Trig[i][j]->GetRMS());
      TF1* func = CosmicP1Trig[i][j]->GetFunction("gaus");
      grSlope->SetPoint( grSlope->GetN(),i*5+j+1, func->GetParameter(1));
      grSlope->SetPointError( grSlope->GetN()-1, 0, func->GetParameter(2));
      CosmicP1TrigLarge[i][j]->Fit("gaus","Q","",
				   CosmicP1Trig[i][j]->GetMean()-1.5*CosmicP1Trig[i][j]->GetRMS(), 
				   CosmicP1Trig[i][j]->GetMean()+1.5*CosmicP1Trig[i][j]->GetRMS());
      func = CosmicP1TrigLarge[i][j]->GetFunction("gaus");
      grSlopeLarge->SetPoint( grSlopeLarge->GetN(), i*5+j+1, func->GetParameter(1));
      grSlopeLarge->SetPointError( grSlopeLarge->GetN()-1,0,func->GetParameter(2));
    }
  }

  for( int i = 0; i< 5; i++){
    can->cd( i +1 );
    CosmicP1UpTrig[i]->Draw();
    for( int j = 0; j < 5; j++){
      CosmicP1Trig[i][j]->SetLineColor(j+1);
      CosmicP1Trig[i][j]->Draw("same");
      CosmicP1TrigLarge[i][j]->Draw("same");
    }
  }
  double sol = 299.97;//[mm/ns]
  TLine* solLine = new TLine( -1, -1./sol, 25, -1./sol);
  //can->cd( 6 );


  TCanvas* can1 = new TCanvas("can1","",800,400);
  can1->Divide( 2,1);
  can1->cd(1);
  grSlope->GetXaxis()->SetRangeUser( -1, 25);  
  grSlope->Draw("AP");
  solLine->SetLineStyle(2);
  solLine->Draw("same");
  TCanvas* can2 = new TCanvas("can2","",1200,800);
  can2->Divide(3,2);
  for( int i = 0; i< 5; i++){
    can2->cd( i+1 );
    CosmicP1TrigLarge[i][0]->Draw();
    for( int j = 0; j< 5; j++){
      CosmicP1TrigLarge[i][j]->Draw("same");
    }
  }
  can2->cd(6);
  grSlopeLarge->Draw("AP");

  
  Double_t H_trig = 2800;
  Double_t R      = 1200;
  TGraph* grDelta1 = new TGraph();
  TGraph* grDelta2 = new TGraph();

  TGraphErrors * grVCluster = new TGraphErrors();

  for( int i = 0; i< 5; i++){
    for( int j  =0; j< 5; j++){
      Double_t iv_0 = TMath::Abs(grSlope->GetY()[ i*5 +j ]);
      Double_t ive_0 = grSlope->GetEY()[ i*5 + j];
      

      Double_t deltaZ = (i-j)*100*R/H_trig;//mm            

      Double_t EdeltaZ = TMath::Sqrt(2)*50*R/H_trig;

      Double_t l  = TMath::Sqrt( R*R + deltaZ*deltaZ);
      Double_t El = deltaZ*EdeltaZ/TMath::Sqrt( R*R + deltaZ*deltaZ); 
      Double_t delta_t0 = l/sol;
      Double_t delta_t1 = iv_0*R - delta_t0;
      Double_t Edelta_t1 = QuadSum(ive_0*R, El/sol);
      
      Double_t V_CsI = deltaZ / delta_t1;
      Double_t EV_CsI = QuadSum( EdeltaZ / delta_t1, Edelta_t1/delta_t1);

      Double_t delta_t1_adj = deltaZ/70.;
      Double_t delta_t1_adj1 = deltaZ/80.;
      Double_t delta_t1_adj2 = deltaZ/90.;
      
      grDelta->SetPoint(grDelta->GetN(), (delta_t0+delta_t1_adj)/R , iv_0);
      grDelta1->SetPoint(grDelta1->GetN(), (delta_t0+delta_t1_adj1)/R , iv_0);
      grDelta2->SetPoint(grDelta2->GetN(), (delta_t0+delta_t1_adj2)/R , iv_0);
      
      if( TMath::Abs(deltaZ) <= 2*EdeltaZ ){ continue; }
      grVCluster->SetPoint( grVCluster->GetN(), i*5+j+1 , V_CsI);
      grVCluster->SetPointError( grVCluster->GetN()-1 , 0, EV_CsI);
      
    }
  }
  can1->cd(2);
  grVCluster->SetMarkerStyle( 6);
  grVCluster->Draw("AP");
  
  grVCluster->Fit("pol0","","",0,26);
  /*
  grDelta1->SetMarkerColor(2);
  grDelta2->SetMarkerColor(3);
  grDelta1->SetMarkerStyle(6);
  grDelta2->SetMarkerStyle(6);


  can1->cd(2);
  grDelta->Draw("AP");
  grDelta1->Draw("P");
  grDelta2->Draw("P");
  
  TF1* func = new TF1("func","x",0,0.1);
  func->Draw("same");

  */


  /*
  for( int i = 0; i< 5; i++){
    CosmicP1UpTrig[i]->Write();
    for( int j  =0 ;j < 5; j++){
      CosmicP1Trig[i][j]->Write();
    }
  }

  tfHist->Close();
  */
}
int evaluate( std::string filelist, std::string outfile )
{
  gStyle->SetOptStat(0);

  TCanvas *ctemp = new TCanvas();

  TCanvas *cres = new TCanvas("TimeDependence");
  TH1F* hres = new TH1F("hres","",100,0,650);
  hres->GetYaxis()->SetRangeUser(0,50);
  hres->SetTitle("");
  hres->GetXaxis()->SetTitle("time (s)");
  hres->GetYaxis()->SetTitle("B_{int} (mT)");
  hres->Draw();
  leg = new TLegend(0.2,0.6,0.9,0.9);
//  leg->SetHeader("The Legend Title"); // option "C" allows to center the header
  leg->SetNColumns(5);

  vector< double > v_Bint;
  vector< double > v_BintErr;
  vector< double > v_Bext;
  vector< double > v_BextErr;

  /* Loop over all lines in input file */
  std::ifstream infilelist(filelist);
  std::string line;

  unsigned colorcounter=38;

  while (std::getline(infilelist, line))
  {
    // skip lines with '#' and empty lines
    if ( line.find("#") != string::npos )
      {
        cout << "Skip line " << line << endl;
        continue;
      }

    if ( line == "" )
      continue;

    //cout << "Processing file " << line << endl;


    TString infilename("data_calib/");
    infilename.Append(line);

    TFile *fin = new TFile( infilename );
    TTree *tin = (TTree*)fin->Get("t");

    ctemp->cd();
    tin->Draw("Bi:time");
    TGraph *gtime = new TGraph(tin->GetEntries(), &(tin->GetV2()[0]), &(tin->GetV1()[0]));
    gtime->SetLineColor(colorcounter);
    colorcounter++;

    TH1F* hBext = new TH1F("hBext","",100,0,1000);
    tin->Draw("Bo >> hBext");

    cres->cd();
    gtime->Draw("lsame");

    double Bext_i = hBext->GetMean();
    double BextErr_i = hBext->GetRMS();

    double Bint_i = gtime->Eval(590);
    double BintErr_i = 0;

    /* add legend entry */
    TString legname("B_ext ~ ");
    legname += (int)Bext_i;
    leg->AddEntry(gtime,legname,"l");

    cout << "B_ext: " << Bext_i << " \t B_int: " << Bint_i << endl;

    v_Bint.push_back(Bint_i);
    v_BintErr.push_back(BintErr_i);
    v_Bext.push_back(Bext_i);
    v_BextErr.push_back(BextErr_i);

  }

  cres->cd();
  leg->Draw();

  TGraphErrors *gfinal = new TGraphErrors(v_Bext.size(), &(v_Bext[0]), &(v_Bint[0]), &(v_BextErr[0]), &(v_BintErr[0]));
  gfinal->Sort();
  gfinal->SetName("Bint_Vs_Bext");
  gfinal->SetTitle("");
  gfinal->GetXaxis()->SetTitle("B_{ext} (mT)");
  gfinal->GetYaxis()->SetTitle("B_{int} (mT)");

  TCanvas *cfinal = new TCanvas();
  gfinal->Draw("APL");

  /* Save output graph */
  TString outfilename("output/");
  outfilename.Append(outfile);
  TFile *fout = new TFile(outfilename,"RECREATE");

  cres->Write();
  gfinal->Write();

  fout->Close();

  /* Write result to txt output file */
  TString outfilenametxt = outfilename;
  outfilenametxt.ReplaceAll(".root",".txt");

  ofstream foutxt;
  foutxt.open( outfilenametxt );
  foutxt <<  "# Bo sig_Bo Bi sig_Bi shield sig_shield sf sig_sf time_dependent" << endl;

  for ( int i = 0; i < gfinal->GetN(); i++ )
  {
    double Bo = gfinal->GetX()[i];
    double sig_Bo = gfinal->GetEX()[i];
    double Bi = gfinal->GetY()[i];
    double sig_Bi = gfinal->GetEY()[i];
    double shield = 0;
    double sig_shield = 0;
    double sf = 0;
    double sig_sf = 0;
    double time_dependent = 0;

    foutxt <<  Bo << " " << sig_Bo << " " << Bi << " " << sig_Bi << " "
         << shield << " " << sig_shield << " " << sf << " " << sig_sf
         << " " << time_dependent << endl;
  }

  return 0;
}
示例#7
0
TGraphErrors *ReadMWGraph(const char *name, Int_t flag)
{
  Double_t xreject = 0.49;

  TGraphErrors *g = new TGraphErrors(name);
  if (g->IsZombie()) return 0;
  while (g->GetX()[0] < xreject)
    g->RemovePoint(0);

  TGraphErrors *g2 = new TGraphErrors(name);
  if (g2->IsZombie()) return 0;
  while (g2->GetX()[0] < xreject)
    g2->RemovePoint(0);
  g2->SetMarkerStyle(4);
  g2->SetMarkerSize(1.00);
  g2->SetMarkerColor(kBlack);
  g2->SetLineColor(kBlack);

  TGraphErrors *gsys = new TGraphErrors(name, "%lg %lg %lg %*lg %lg");
  if (gsys->IsZombie()) return 0;
  while (gsys->GetX()[0] < xreject)
    gsys->RemovePoint(0);
  for (Int_t i = 0; i < gsys->GetN(); i++)
    gsys->SetPointError(i, gsys->GetErrorX(i)*0.75, gsys->GetErrorY(i));
  gsys->SetFillColor(kGray+2);
  gsys->SetLineColor(kGray+2);
  gsys->SetFillStyle(3000);

  if (flag == 1 || flag == 3) {
    TGraphErrors *gt = new TGraphErrors(Form("%s_%s", name, "trues"));
    if (gt->IsZombie()) return 0;
    while (gt->GetX()[0] < xreject)
      gt->RemovePoint(0);
    gt->SetMarkerStyle(20);
    gt->SetMarkerSize(0.75);
    gt->SetMarkerColor(kGreen+1);
    gt->SetLineColor(kGreen+1);

    TGraphErrors *gbw = new TGraphErrors(Form("%s_%s", name, "gen"));
    if (gbw->IsZombie()) return 0;
    while (gbw->GetX()[0] < xreject)
      gbw->RemovePoint(0);
    gbw->SetMarkerStyle(20);
    gbw->SetMarkerSize(0.75);
    gbw->SetMarkerColor(kBlue+1);
    gbw->SetLineColor(kBlue+1);

    for (Int_t i = 0; i < g->GetN(); i++) {
      g->SetPointError(i, g->GetEX()[i], 0.);
      gt->SetPointError(i, gt->GetEX()[i], 0.);
      gbw->SetPointError(i, gbw->GetEX()[i], 0.);
    }

    for (Int_t i = 0; i < g2->GetN(); i++) {
      g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i] - gt->GetY()[i] + gbw->GetY()[i]);
      g2->SetPointError(i, g2->GetEX()[i], TMath::Sqrt(g2->GetEY()[i]*g2->GetEY()[i] + gt->GetEY()[i]*gt->GetEY()[i] +
                                                       gbw->GetEY()[i]*gbw->GetEY()[i]));

      //      g2->SetPoint(i, g2->GetX()[i], g2->GetY()[i] - gt->GetY()[i] + 1.01947);
      //      g2->SetPointError(i, g2->GetEX()[i], TMath::Sqrt(g2->GetEY()[i]*g2->GetEY()[i] + gt->GetEY()[i]*gt->GetEY()[i] +
      //                                                       7.78680e-06*7.78680e-06));

      gsys->SetPoint(i, gsys->GetX()[i], g2->GetY()[i]);
    }
  }

  g->SetTitle();
  g->SetName(name);
  g->GetXaxis()->SetTitle("p_{T}, GeV/c");
  g->SetMarkerStyle(20);
  g->SetMarkerSize(0.95);
  g->SetMarkerColor(kRed+1);
  g->SetLineColor(kRed+1);

  const Double_t mass = 1.019455;
  const Double_t mass_delta = 0.000020;
  const Double_t width = 0.00426;
  const Double_t width_delta = 0.00004;
  if (flag == 1) { // mass
    g->GetYaxis()->SetTitleOffset(1.50);
    g->GetYaxis()->SetTitle("mass, GeV/c^{2}");
    g->SetMaximum(mass+0.0015);
    g->SetMinimum(mass-0.0015);
    TBox *box = new TBox(g->GetXaxis()->GetXmin(), mass - mass_delta, g->GetXaxis()->GetXmax(), mass + mass_delta);
    box->SetFillColor(kGray+1);
    box->SetFillStyle(3001);
    g->GetListOfFunctions()->Add(box);
    g->GetListOfFunctions()->Add(g2, "CP");
    g->GetListOfFunctions()->Add(gt, "CP");
    g->GetListOfFunctions()->Add(gbw, "CP");
  }
  else if (flag == 3) { // mass simple
    g2->SetTitle();
    g2->SetName(Form("%s_only", name));
    g2->GetXaxis()->SetTitle("p_{T}, GeV/c");
    g2->SetMarkerStyle(20);
    g2->SetMarkerSize(0.75);
    g2->SetMarkerColor(kBlack);
    g2->SetLineColor(kBlack);
    g2->GetYaxis()->SetTitleOffset(1.50);
    g2->GetYaxis()->SetTitle("mass, GeV/c^{2}");
    g2->SetMaximum(mass+0.0015);
    g2->SetMinimum(mass-0.0015);
    TBox *box = new TBox(g->GetXaxis()->GetXmin(), mass - mass_delta, g2->GetXaxis()->GetXmax(), mass + mass_delta);
    box->SetFillColor(kGray+1);
    box->SetFillStyle(3001);
    g2->GetListOfFunctions()->Add(box);
    g2->GetListOfFunctions()->Add(gsys, "E5");
    return g2;
  }
  else if (flag == 2) { // width
    g->SetTitle();
    g->SetName(name);
    g->GetXaxis()->SetTitle("p_{T}, GeV/c");
    g->SetMarkerStyle(20);
    g->SetMarkerSize(0.75);
    g->SetMarkerColor(kBlack);
    g->SetLineColor(kBlack);
    g->GetYaxis()->SetTitleOffset(1.50);
    g->GetYaxis()->SetTitle("width, GeV/c^{2}");
    g->SetMaximum(0.01);
    g->SetMinimum(0.0);
    TBox *box = new TBox(g->GetXaxis()->GetXmin(), width - width_delta, g->GetXaxis()->GetXmax(), width + width_delta);
    box->SetFillColor(kGray+1);
    box->SetFillStyle(3001);
    g->GetListOfFunctions()->Add(box);
    g->GetListOfFunctions()->Add(gsys, "E5");
  }

  return g;
}
示例#8
0
void disceff(TString filename) {
	gROOT->SetStyle("Plain");
	
	TString cmssw;
	// 167
	
	cmssw = "$3.1.0_pre9$";
		
	TFile *f = TFile::Open(filename);

	std::vector< TString > taggers;
	taggers.push_back( "TC2" );
	taggers.push_back( "TC3" );
	taggers.push_back( "TP" );
	taggers.push_back( "BTP" );
	taggers.push_back( "SSV" );
	taggers.push_back( "CSV" );
	taggers.push_back( "MSV" );
	taggers.push_back( "SMT" );
	taggers.push_back( "SETbyIP3d" );
	taggers.push_back( "SETbyPt" );
	taggers.push_back( "SMTbyIP3d" );
	taggers.push_back( "SMTbyPt" );

	std::vector< TString > discriminators;
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
		discriminators.push_back( "disc"+taggers[itagger]+"_udsg" );
	}
//	discriminators.push_back( "discTC3_udsg" );
//	discriminators.push_back( "discTP_udsg" );

	const int dim=taggers.size();
        TCanvas *cv[dim];
	TMultiGraph* mg[dim];
	for ( size_t itagger = 0; itagger < taggers.size(); ++itagger ) {
		TString tag = "g"+taggers[itagger]+"_udsg";
		TString tagb = "g"+taggers[itagger]+"_b";
		TString tagc = "g"+taggers[itagger]+"_c";
		cv[itagger] = new TCanvas("cv_"+taggers[itagger],"cv_"+taggers[itagger],700,700);
		TLegend *legend0 = new TLegend(0.68,0.70,0.88,0.90);

		TGraphErrors *agraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tag);
		TGraphErrors *bgraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tagb);
		TGraphErrors *cgraph = (TGraphErrors*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+tagc);

		TGraph *dgraph = (TGraph*) gDirectory->Get("BTagPATAnalyzer"+taggers[itagger]+"/"+taggers[itagger]+"/"+discriminators[itagger]);
		TGraph *bvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),bgraph->GetY());
		TGraph *cvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),cgraph->GetY());
		TGraph *lvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),agraph->GetY());
		TGraph *udsgvsdgraph = new TGraph(dgraph->GetN(),dgraph->GetY(),dgraph->GetX());
		dgraph->Sort();
//		udsgvsdgraph->Sort();
//		udsgvsdgraph->SetLineColor(1);
//              legend0 -> AddEntry(udsgvsdgraph,"control","l");
		lvsdgraph->Sort();
		lvsdgraph->SetLineColor(2);
                legend0 -> AddEntry(lvsdgraph,tag,"l");
		cvsdgraph->Sort();
		cvsdgraph->SetLineColor(3);
                legend0 -> AddEntry(cvsdgraph,tagc,"l");
		bvsdgraph->Sort();
		bvsdgraph->SetLineColor(4);
                legend0 -> AddEntry(bvsdgraph,tagb,"l");
		mg[itagger]= new TMultiGraph();
//		mg[itagger]->Add(udsgvsdgraph);
		mg[itagger]->Add(lvsdgraph);
		mg[itagger]->Add(cvsdgraph);
		mg[itagger]->Add(bvsdgraph);
//		mg[itagger]->Add(dgraph);

		cv[itagger]->cd(1);
		mg[itagger]->Draw("ALP");
		mg[itagger]->GetYaxis()->SetTitle("eff");
		mg[itagger]->GetXaxis()->SetTitle("discriminant");
		legend0 -> Draw();
		cv[itagger]->Update();
	        cv[itagger]->cd(0);
		cv[itagger]-> Print ("BTagPATeff_vs_disc"+taggers[itagger]+".eps");
		cv[itagger]-> Print ("BTagPATeff_vs_disc"+taggers[itagger]+".ps");

		TGraphErrors *g = new TGraphErrors(agraph->GetN(),agraph->GetY(),agraph->GetX(),agraph->GetEY(),agraph->GetEX());
		g->Sort();
		g->SetLineColor(itagger+1);

		std::cout << " Tagger: " << tag << std::endl;
		std::cout << " Loose(10%): " << " cut > " << std::setprecision(4) << dgraph->Eval(0.1) << " b-eff = " << g->Eval(0.1) << std::endl;
		std::cout << " Medium(1%):  " << " cut > " << std::setprecision(4) << dgraph->Eval(0.01) << " b-eff = " << g->Eval(0.01) << std::endl;
		std::cout << " Tight(0.1%) = " << " cut > " << std::setprecision(4) << dgraph->Eval(0.001) << " b-eff = " << g->Eval(0.001) << std::endl;

	}//end for
 
	
}
示例#9
0
void Drawmethodcomp(){ 
 const int nDil = 8;
 const double centDil[nDil+1] = {1.0,0.7,0.6,0.5,0.4,0.3,0.2,0.1,0};
 double centDilbin[nDil];
for(int i=0;i<nDil;i++)
  centDilbin[i]=0.29+i+N-1-nDil;
 const double NpartDil[nDil] = {8.75,30.51,53.30,86.23,130.06,187.35,261.49,355.45};
 const double NpartDilerr[nDil] = {1.13,3.02,3.95,4.35,4.60,4.44,3.96,2.83};
 const double NcollDil[nDil] = {8.01,38.86,86.85,175.76,326.06,563.21,926.79,1484.49};
 const double NcollDilerr[nDil] = {1.41,6.41,12.48,21.13,34.27,52.66,81.37,120.0};
 TGraphErrors *graphNpartDil = new TGraphErrors(nDil,centDilbin,NpartDil,0,NpartDilerr);
 TGraphErrors *graphNcollDil = new TGraphErrors(nDil,centDilbin,NcollDil,0,NcollDilerr);
 TCanvas *c1 = new TCanvas("c1","c1",1,1,550,460);
 c1->SetLogy();
  c1->SetFillColor(10);
  c1->SetFrameFillColor(0);
  c1->SetFrameBorderSize(0);
  c1->SetFrameBorderMode(0);
  c1->SetLeftMargin(0.15);
  c1->SetBottomMargin(0.15);
  c1->SetTopMargin(0.02);
  c1->SetRightMargin(0.02);
  gStyle->SetOptStat(0);
  c1->SetTicks(-1);

	N=N-1;
 TString str="Ncoll";
 TH1D* hist = new TH1D("","",N,0,N);
 hist->GetXaxis()->SetNdivisions(502);
if(method==0)
 hist->SetXTitle("Centrality");
else
 hist->SetXTitle("HF #Sigma E_{T} |#eta|>3");
 hist->SetYTitle(Form("<%s> and systematic errors",str.Data()));
 hist->SetMinimum(1);
 hist->SetMaximum(3999.99);
 hist->GetXaxis()->CenterTitle(0);
 hist->GetYaxis()->CenterTitle(1);
 hist->GetYaxis()->SetTitleOffset(1.1);
 hist->GetXaxis()->SetTitleOffset(1.1);
 hist->GetXaxis()->SetTitleSize(0.056);
 hist->GetYaxis()->SetTitleSize(0.056);
 hist->GetXaxis()->SetLabelSize(0.05);
 hist->GetYaxis()->SetLabelSize(0.05);
hist->GetXaxis()->SetLabelOffset(99);
hist->Draw();
	
	TFile *f=TFile::Open(outG);
	TGraphErrors* graph = (TGraphErrors*)f->Get(Form("std/%s_graph",str.Data()));
//	TGraphErrors* Gri055_graph = (TGraphErrors*)f->Get(Form("Gri055/%s_graph",str.Data()));
//	TGraphErrors* Gri101_graph = (TGraphErrors*)f->Get(Form("Gri101/%s_graph",str.Data()));
        TVectorD *centbin = (TVectorD*)f->Get(Form("std/G0/centbin"));
        TVectorD *kpoint = (TVectorD*)f->Get(Form("std/G0/kpoint"));

	TFile *f1=TFile::Open(Form("../../OneComp/double_side/%s",outG.Data()));
	TGraphErrors* graph1 = (TGraphErrors*)f1->Get(Form("std/%s_graph",str.Data()));
//	TGraphErrors* Gri055_graph = (TGraphErrors*)f->Get(Form("Gri055/%s_graph",str.Data()));
//	TGraphErrors* Gri101_graph = (TGraphErrors*)f->Get(Form("Gri101/%s_graph",str.Data()));
        TVectorD *centbin1 = (TVectorD*)f1->Get(Form("std/G0/centbin"));
        TVectorD *kpoint1 = (TVectorD*)f1->Get(Form("std/G0/kpoint"));

graph->SetTitle("g1");
graph->SetMarkerStyle(20);
graph->SetMarkerColor(1);
graph->SetLineColor(1);
graph->SetLineWidth(2);
graph->SetMarkerSize(1.2);
graph->Draw("Psameez");

graph1->SetMarkerStyle(24);
graph1->SetMarkerColor(4);
graph1->SetLineColor(4);
graph1->SetLineWidth(2);
graph1->SetMarkerSize(1.2);
graph1->Draw("Psameez");
/*
Gri055_graph->SetTitle("g2");
Gri055_graph->SetMarkerStyle(33);
Gri055_graph->SetMarkerColor(2);
Gri055_graph->SetLineColor(2);
Gri055_graph->SetLineWidth(2);
Gri055_graph->SetMarkerSize(1.2);
Gri055_graph->Draw("Psameez");

Gri101_graph->SetTitle("g3");
Gri101_graph->SetMarkerStyle(34);
Gri101_graph->SetMarkerColor(4);
Gri101_graph->SetLineColor(4);
Gri101_graph->SetLineWidth(2);
Gri101_graph->SetMarkerSize(1.2);
Gri101_graph->Draw("Psameez");
*/
 graphNpartDil->SetMarkerSize(1.2);
 graphNpartDil->SetLineColor(2);
 graphNpartDil->SetLineWidth(2);
 graphNpartDil->SetMarkerStyle(33);
 graphNpartDil->SetMarkerColor(2);
 graphNcollDil->SetMarkerSize(1.2);
 graphNcollDil->SetLineColor(2);
 graphNcollDil->SetLineWidth(2);
 graphNcollDil->SetMarkerStyle(33);
 graphNcollDil->SetMarkerColor(2);
if(str=="Npart") graphNpartDil->Draw("Psame");
if(str=="Ncoll") graphNcollDil->Draw("Psame");
std::vector<TString> label(N);
for(int i=0;i<N;i++)
        if(method==0)label[i] = Form("%.2f-%.2f%%",(*centbin)[i]*100,(*centbin)[i+1]*100);
        else label[i] = Form("%.2f-%.2f",(*kpoint)[i],(*kpoint)[i+1]);

    TLatex *tex1= new TLatex(0.2,0.9,"CMS Preliminary PbPb #sqrt{s_{NN}} = 2.76 TeV");
    tex1->SetNDC();
    tex1->SetTextColor(1);
    tex1->SetTextFont(42);
    tex1->SetTextSize(0.05);
    tex1->Draw();

double y = gPad->GetUymin();
// - 0.2*h->GetYaxis()->GetBinWidth(1);
   TText t;
   t.SetTextAngle(45);
   t.SetTextSize(0.03);
   t.SetTextAlign(33);
   for (int i=0;i<N;i++) {
      double x = hist->GetXaxis()->GetBinCenter(i+1);
      t.DrawText(x,y,label[i]);
   }
TLegend *leg0 = new TLegend(0.18,0.70,0.50,0.85);
    leg0->SetFillColor(10);
    leg0->SetBorderSize(0);
    leg0->SetTextFont(42);
    leg0->SetTextSize(0.047);
    leg0->AddEntry(graph,"From Ancestor fitting","p");
    leg0->AddEntry(graph1,"From One Comp fitting","p");
//    leg0->AddEntry(Gri055_graph,"Gribov #Omega=0.55","p");
//    leg0->AddEntry(Gri101_graph,"Gribov #Omega=1.01","p");
 if(str=="Npart")   leg0->AddEntry(graphNpartDil,"Npart from run I","p");
 if(str=="Ncoll")   leg0->AddEntry(graphNcollDil,"Ncoll from run I","p");
	leg0->Draw();	
c1->SaveAs(Form("%sGri.png",str.Data()));
c1->SaveAs(Form("%sGri.pdf",str.Data()));


 TCanvas *c2 = new TCanvas("c2","c2",1,1,550,460);
  c2->SetFillColor(10);
  c2->SetFrameFillColor(0);
  c2->SetFrameBorderSize(0);
  c2->SetFrameBorderMode(0);
  c2->SetLeftMargin(0.15);
  c2->SetBottomMargin(0.15);
  c2->SetTopMargin(0.02);
  c2->SetRightMargin(0.02);
  c2->SetTicks(-1);
c2->cd();
TGraphErrors* fdvf1 = (TGraphErrors*)graph->Clone("fdvf1");
TGraphErrors* f1dvDil = (TGraphErrors*)graph->Clone("f1dvDil");
TGraphErrors* fdvDil = (TGraphErrors*)graph->Clone("fdvDil");
TGraphErrors* Dilsys = (TGraphErrors*)graph->Clone("Dilsys");
TGraphErrors* Dilsys2 = (TGraphErrors*)graph->Clone("Dilsys2");
for(int ip = 0;ip<fdvf1->GetN();ip++){
    double x = graph->GetX()[ip];
    double ey = graph->GetEY()[ip];
    double y = graph->GetY()[ip];
    double ey1 = graph1->GetEY()[ip];
    double y1 = graph1->GetY()[ip];
    double eyNcoll = graphNcollDil->GetEY()[ip];
    double yNcoll = graphNcollDil->GetY()[ip];
    double eyNpart = graphNpartDil->GetEY()[ip];
    double yNpart = graphNpartDil->GetY()[ip];
    if(y1!=0 && y!=0){
        fdvf1->SetPoint(ip,x,y/y1);
        fdvf1->SetPointError(ip,0,y/y1*sqrt((ey/y)**2+(ey1/y1)**2));
        if(str=="Ncoll"){
        fdvDil->SetPoint(ip,x,y/yNcoll);
        double yerr = y/yNcoll*sqrt((ey/y)**2+(eyNcoll/yNcoll)**2);
        fdvDil->SetPointError(ip,0,0);
        f1dvDil->SetPoint(ip,x,y1/yNcoll);
        double y1err = y1/yNcoll*sqrt((ey1/y1)**2+(eyNcoll/yNcoll)**2);
        f1dvDil->SetPointError(ip,0,0);
        Dilsys->SetPoint(ip,x,1.);
        Dilsys->SetPointError(ip,0,TMath::Max(fabs(y1/yNcoll-1),fabs(y/yNcoll-1)));
        Dilsys2->SetPoint(ip,x,1.);
        Dilsys2->SetPointError(ip,0,TMath::Max(yerr,y1err));
        }
        else if(str=="Npart"){
        fdvDil->SetPoint(ip,x,y/yNpart);
        double yerr = y/yNpart*sqrt((ey/y)**2+(eyNcoll/yNpart)**2);
        fdvDil->SetPointError(ip,0,0);
        f1dvDil->SetPoint(ip,x,y1/yNpart);
        double y1err = y1/yNpart*sqrt((ey1/y1)**2+(eyNcoll/yNcoll)**2);
        f1dvDil->SetPointError(ip,0,0);
        Dilsys->SetPoint(ip,x,1.);
        Dilsys->SetPointError(ip,0,TMath::Max(fabs(y1/yNpart-1),fabs(y/yNpart-1)));
        Dilsys2->SetPoint(ip,x,1.);
        Dilsys2->SetPointError(ip,0,TMath::Max(yerr,y1err));
        }
}
}
hist->SetMinimum(0.5);
hist->SetMaximum(1.5);
hist->SetYTitle(Form("<%s> ratio",str.Data()));
hist->Draw();
fdvf1->SetMarkerStyle(20);
fdvf1->SetMarkerColor(1);
fdvf1->SetLineColor(1);
fdvf1->SetLineWidth(2);
fdvf1->SetMarkerSize(1.4);
//fdvf1->Draw("Psameez");
f1dvDil->SetMarkerStyle(24);
f1dvDil->SetMarkerColor(2);
f1dvDil->SetLineColor(2);
f1dvDil->SetLineWidth(2);
f1dvDil->SetMarkerSize(1.4);
fdvDil->SetMarkerStyle(20);
fdvDil->SetMarkerColor(4);
fdvDil->SetLineColor(4);
fdvDil->SetLineWidth(2);
fdvDil->SetMarkerSize(1.4);
Dilsys->SetFillColor(kYellow+2);
Dilsys2->SetFillColor(kYellow+1);
//Dilsys2->Draw("e3same");
Dilsys->Draw("e3same");
fdvDil->Draw("Psameez");
f1dvDil->Draw("Psameez");
tex1->Draw();
TLine *l = new TLine(0,1,N,1);
l->SetLineStyle(2);
l->SetLineWidth(3);
l->Draw("same");
TLegend *leg1 = new TLegend(0.38,0.72,0.75,0.86);
    leg1->SetFillColor(10);
    leg1->SetBorderSize(0);
    leg1->SetTextFont(42);
    leg1->SetTextSize(0.04);
    //leg1->AddEntry(fdvf1,"Ancestor fitting/One Comp fitting","p");
    leg1->AddEntry(f1dvDil,"One Component fitting/Run I fitting","p");
    leg1->AddEntry(fdvDil,"Two Component fitting/Run I fitting","p");
    leg1->AddEntry(Dilsys,"RunI fitting systematics","f");
  //  leg1->AddEntry(Dilsys2,"RunI fitting ratio systematics","f");
    double y = gPad->GetUymin()+0.5;
   for (int i=0;i<N;i++) {
      double x = hist->GetXaxis()->GetBinCenter(i+1);
      t.DrawText(x,y,label[i]);
   }
   leg1->Draw();
c2->SaveAs(Form("%sGriratio.png",str.Data()));
c2->SaveAs(Form("%sGriratio.pdf",str.Data()));
}
示例#10
0
int postprocessingSysError(){

  cout<<endl<<endl<<endl<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Postproccess all systematic uncertainties! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl;
  gErrorIgnoreLevel = 1001;

  const TString method  = "RMS99";
  const TString type    = "PFCHS";

  const int nEta =4;
  double eta_bins[5] = {0., 0.5, 1.1, 1.7, 2.3};
  // For looking at different systematic uncertainties independently
  const bool QCD    = true;
  const bool JEC    = true;
  const bool flavor = true;
  const bool PU     = true;
  const bool MC     = true;
  

  TString etaString, filename;   

  TString rootFiles, AuxString;  
  TString JetType = "PFCHS";
  TString Method  = "RMS99";   

  double *ratioEtaBinnedX  = new double[nEta];
  double *ratioEtaBinnedY  = new double[nEta];
  double *ratioEtaBinnedEX = new double[nEta];
  double *ratioEtaBinnedEY = new double[nEta];

  double *ratioEtaBinnedQCDUpY   = new double[nEta];
  double *ratioEtaBinnedQCDDownY = new double[nEta];

  TF1 *QCDuncertainty;

  if(QCD){
    rootFiles   = (TString) "scripts/plotsQCD/FinalErrorsQCD_" + type + (TString) "_" + method + (TString) ".root";
    TFile *_file = TFile::Open(rootFiles);    
    _file->GetObject("function",QCDuncertainty);
  }
  
  for(int eta = 0; eta < nEta; eta++){
    
    //cout<< endl<<endl<<endl<<eta+1<<". eta Bin!!"<<endl;

    // Read the MC and data results 
    rootFiles = (TString) "root_files_FINAL_data/Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + JetType + (TString) "_data_" + Method + (TString) ".root";
    TGraphErrors* JERData = readTGraphErrors(rootFiles,"Graph;1","Graph");
    rootFiles = (TString) "root_files_FINAL_mc/Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + JetType + (TString) "_mc_" + Method + (TString) ".root";
    TGraphErrors* JERMC = readTGraphErrors(rootFiles,"Graph","Graph");
    
    if(eta+1 == 1) etaString = Form("JER for |#eta| < %4.1f",etaBins[eta+1]);
    else           etaString = Form("JER for %4.1f <|#eta|< %4.1f",etaBins[eta+1],etaBins[eta+2]);
 
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // 1.) Calculate the ratio w/o systematic Uncertainties  


    int nData    = JERData->GetN();

    double *dataX  = JERData->GetX();
    double *dataY  = JERData->GetY();
    double *dataEX = JERData->GetEX();
    double *dataEY = JERData->GetEY();
    
    double *mcX  = new double[nData];
    double *mcY  = new double[nData];
    double *mcEX = new double[nData];
    double *mcEY = new double[nData];
    
    double *ratioX  = new double[nData];
    double *ratioY  = new double[nData];
    double *ratioEX = new double[nData];
    double *ratioEY = new double[nData];


    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    // Initialize some stuff for QCD uncertainty
    double *ratioQCDUpY    = new double[nData];
    double *ratioQCDDownY  = new double[nData];    
    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 
    int idx = 0;
    for(int i=0; i<nData; i++){

      JERMC   -> GetPoint(idx,mcX[i],mcY[i]);
      mcEX[i] = JERMC -> GetErrorX(idx);
      mcEY[i] = JERMC -> GetErrorY(idx);

      idx += 1;

      if(TMath::Abs(dataX[i]/mcX[i] - 1.) > 0.1){
	i -= 1;
	continue;
      }
     
      ratioX[i]  = 1./2.*(dataX[i] + mcX[i]);
      ratioY[i]  = dataY[i]/mcY[i];
      ratioEX[i] = 1./2.*TMath::Sqrt(TMath::Power(dataEX[i],2)+TMath::Power(mcEX[i],2));
      ratioEY[i] = TMath::Sqrt(TMath::Power((1./mcY[i]),2)*TMath::Power(dataEY[i],2)+TMath::Power((dataY[i]/(TMath::Power(mcY[i],2))),2)*TMath::Power(mcEY[i],2));
      if(QCD){
	// For QCD
	ratioQCDUpY[i]   = ratioY[i]*(1. + QCDuncertainty->Eval(ratioX[i]));
	ratioQCDDownY[i] = ratioY[i]*(1. - QCDuncertainty->Eval(ratioX[i]));
	//cout<<"QCDuncertainty->Eval(ratioX[i]) = "<<QCDuncertainty->Eval(ratioX[i])<<endl;
      }
    }
    
    TGraphErrors *Ratio = new TGraphErrors(nData,ratioX,ratioY,ratioEX,ratioEY);


    // For QCD
    TGraphErrors *QCDUp   = new TGraphErrors(nData,ratioX,ratioQCDUpY,ratioEX,ratioEY);
    TGraphErrors *QCDDown = new TGraphErrors(nData,ratioX,ratioQCDDownY,ratioEX,ratioEY);
    

    if(eta+1 == 1 ) AuxString = Form("Ratio between Data and MC for |#eta| < %4.1f",etaBins[eta+1]);
    else            AuxString = Form("Ratio between Data and MC for %4.1f <|#eta|<%4.1f",etaBins[eta+1],etaBins[eta+2]);
 
    Ratio -> SetTitle(AuxString); 
    Ratio -> GetXaxis() -> SetTitle("Photon pT");
    Ratio -> GetXaxis() -> SetTitleOffset(1.1); 
    Ratio -> GetYaxis() -> SetTitle("Ratio of JER (DATA/MC)");
    Ratio -> GetYaxis() -> SetTitleOffset(1.2);   
    Ratio -> GetXaxis() -> SetLimits(0,600);
    TF1* f1 = new TF1("name","pol0",0,600);   
    Ratio -> Fit("name","QR");
    

    TF1* fitQCDUp  = new TF1("fitQCDUp","pol0",0,600); 
    TF1* fitQCDDown = new TF1("fitQCDDown","pol0",0,600); 
    if(QCD){
      // For QCD
      QCDUp   -> Fit("fitQCDUp","QR");
      QCDDown -> Fit("fitQCDDown","QR");
    }
    
    TLegend *legend  = 0;
    legend = new TLegend(0.55,0.8,0.9,0.9);
    legend -> SetFillColor(0);

    legend -> SetHeader(Form(" %4.3f #pm %4.3f", f1 -> GetParameter(0), f1->GetParError(0)));
    TCanvas *c11 = new TCanvas("c11",AuxString,200,10,500,500);
    c11 -> cd();
    Ratio -> SetMinimum(0.5);
    Ratio -> SetMaximum(2.0);
  
    Ratio  -> Draw("AP"); 
    legend -> Draw("same");
  
    TLatex*  info   = new TLatex();
    info-> SetNDC();
    info->SetTextSize(0.045); 
    info->DrawLatex(0.22,0.84,Form("#splitline{#chi^{2} = %4.2f}{dof = %i}",f1 -> GetChisquare(),f1 -> GetNDF()));
  
    filename = (TString) "plots/Ratio_Resolution_for_" + (long) (eta+1) + (TString) "_eta_bin_" + type + (TString) "_data_comparison_" + method + (TString) ".pdf";
    c11 -> SaveAs(filename);
    delete c11;
    
    ratioEtaBinnedX[eta]  = (eta_bins[eta+1] + eta_bins[eta])/2.; 
    ratioEtaBinnedY[eta]  = f1 -> GetParameter(0);
    ratioEtaBinnedEX[0]=0.25;
    ratioEtaBinnedEX[1]=0.3;
    ratioEtaBinnedEX[2]=0.3;
    ratioEtaBinnedEX[3]=0.3;
    ratioEtaBinnedEY[eta] = f1->GetParError(0);

    if(QCD){
      ratioEtaBinnedQCDUpY[eta]  = fitQCDUp   -> GetParameter(0);
      ratioEtaBinnedQCDDownY[eta]= fitQCDDown -> GetParameter(0);



      // Some additional stuff for QCD uncertainty
      TCanvas *plotsQCD = new TCanvas("plotsQCD","plotsQCD",200,10,500,500);
      plotsQCD -> cd();

      Ratio -> SetMarkerColor(1);
      Ratio -> SetLineColor(1);
      Ratio -> SetMarkerStyle(20);
      Ratio -> GetFunction("name")->SetLineColor(1);
      QCDUp -> SetMarkerColor(3);
      QCDDown -> SetMarkerColor(3);
      QCDUp  -> SetLineColor(3);
      QCDDown  -> SetLineColor(3);
      QCDUp -> SetMarkerStyle(20);
      QCDDown -> SetMarkerStyle(20);
      QCDUp -> SetMarkerSize(0.8);
      QCDDown -> SetMarkerSize(0.8);
      QCDUp   -> GetFunction("fitQCDUp")->SetLineColor(3);
      QCDDown -> GetFunction("fitQCDDown")->SetLineColor(3);
      Ratio -> Draw("AP");
      QCDUp -> Draw("sameP");
      QCDDown -> Draw("sameP");

      delete legend;
      legend = new TLegend(0.4,0.8,0.9,0.9);
      legend -> SetFillColor(0);
      legend -> SetTextSize(0.045);
      legend -> AddEntry(Ratio,"Central Value","l");
      legend -> AddEntry(QCDUp,Form("Upward variation: + %4.3f",abs(ratioEtaBinnedQCDUpY[eta]/ratioEtaBinnedY[eta]-1.)),"l");
      legend -> AddEntry(QCDDown,Form("Downward variation: - %4.3f",abs(ratioEtaBinnedQCDDownY[eta]/ratioEtaBinnedY[eta]-1.)),"l");
   
      legend -> Draw("same");
      filename = (TString) "plots/plotsQCD_for_" + (long) (eta+1) + (TString) "_bin_"  + type + (TString) "_" + method + (TString) ".pdf";
      plotsQCD -> SaveAs(filename);
      delete plotsQCD;
    }


  }

  TGraphErrors* ratioEtaBinned = new TGraphErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ratioEtaBinnedEX,ratioEtaBinnedEY);
  filename = (TString) "plots/RatioEtaBinned_" + type + (TString) "_" + method + (TString) ".root";
  TFile *f = new TFile(filename,"RECREATE");
  f -> WriteTObject(ratioEtaBinned,"Graph");
  f->Close();
  delete f;

  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 1.) Calculate sys Error from QCD contamination
  //cout<<endl;
    
  double deltaRatioUpQCD[nEta]      = {0.};
  double deltaRatioDownQCD[nEta]    = {0.};
 
  if(QCD){
    
    for(int eta = 0; eta<nEta; eta++){

      deltaRatioUpQCD[eta]     = abs(ratioEtaBinnedQCDUpY[eta]/ratioEtaBinnedY[eta]-1.); 
      deltaRatioDownQCD[eta]   = abs(ratioEtaBinnedQCDDownY[eta]/ratioEtaBinnedY[eta]-1.); 
      
      //cout<<"ratioEtaBinnedQCDDownY[eta]"<<ratioEtaBinnedQCDDownY[eta]<<endl;
      //cout<<"ratioEtaBinnedY[eta]"<<ratioEtaBinnedY[eta]<<endl;
      //cout<<"deltaRatioUpQCD["<<eta<<"] = "<<deltaRatioUpQCD[eta]<<endl;
      //cout<<"deltaRatioDownQCD["<<eta<<"] = "<<deltaRatioDownQCD[eta]<<endl;
    }

  } 
  
  

  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 2.) Calculate sys Error from JEC uncertainty (percentage change of MC result)
  //cout<<endl;

  double deltaRatioUpJEC[nEta]      = {0.};
  double deltaRatioDownJEC[nEta]    = {0.};
    
  if(JEC){

    rootFiles                          = (TString) "scripts/plotsJEC/FinalEtaBinnedErrorsJECUp_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *JECuncertaintyUp  = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelJECUp       = JECuncertaintyUp -> GetY();

    rootFiles                          = (TString) "scripts/plotsJEC/FinalEtaBinnedErrorsJECLow_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *JECuncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelJECLow      = JECuncertaintyLow -> GetY();
      
    for(int eta = 0; eta<nEta; eta++){

      deltaRatioUpJEC[eta]   = sysRelJECUp[eta];
      deltaRatioDownJEC[eta] = sysRelJECLow[eta];

      //cout<<"deltaRatioUpJEC["<<eta<<"] = "<<deltaRatioUpJEC[eta]<<endl;
      //cout<<"deltaRatioDownJEC["<<eta<<"] = "<<deltaRatioDownJEC[eta]<<endl;     

    }

  }
 
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 3.) Calculate sys Error from Flavor uncertainty (percentage change of MC result)
  //cout<<endl;
  
  // Multiply on mc (as symmetric Error)
  // ratioUp  = 1/(1 - delta) * ratio
  // ratioLow = 1/(1 + delta) * ratio

  double deltaRatioUpFlavor[nEta]      = {0.};
  double deltaRatioDownFlavor[nEta]    = {0.};

  if(flavor){

    rootFiles                          = (TString) "scripts/plotsFlavor/FinalEtaBinnedErrorsFlavorUp_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *FlavoruncertaintyUp  = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelFlavorUp       = FlavoruncertaintyUp -> GetY();
    
    rootFiles                          = (TString) "scripts/plotsFlavor/FinalEtaBinnedErrorsFlavorLow_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *FlavoruncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelFlavorLow      = FlavoruncertaintyLow -> GetY();
  
    
    for(int eta = 0; eta<nEta; eta++){

      deltaRatioUpFlavor[eta]   = sysRelFlavorUp[eta];
      deltaRatioDownFlavor[eta] = sysRelFlavorLow[eta];

      //cout<<"deltaRatioUpFlavor["<<eta<<"] = "<<deltaRatioUpFlavor[eta]<<endl;
      //cout<<"deltaRatioDownFlavor["<<eta<<"] = "<<deltaRatioDownFlavor[eta]<<endl;
    }

  }
 
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 4.) Calculate sys Error from PU uncertainty (percentage change of MC result)
  //cout<<endl;

  double deltaRatioUpPU[nEta]      = {0.};
  double deltaRatioDownPU[nEta]    = {0.};
  
  if(PU){
    
    rootFiles                          = (TString) "scripts/plotsPU/FinalEtaBinnedErrorsPUUp_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *PUuncertaintyUp  = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelPUUp       = PUuncertaintyUp -> GetY();

    rootFiles                          = (TString) "scripts/plotsPU/FinalEtaBinnedErrorsPULow_" + type + (TString) "_" + method + (TString) ".root"; 
    TGraphErrors *PUuncertaintyLow = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelPULow      = PUuncertaintyLow -> GetY();
  
    // Multiply on mc (as symmetric Error)
    // ratioUp = 1/(1 - delta) * ratio
    // ratioUp = 1/(1 + delta) * ratio
        
    for(int eta = 0; eta<nEta; eta++){
    
      deltaRatioUpPU[eta]   = sysRelPUUp[eta];
      deltaRatioDownPU[eta] = sysRelPULow[eta];

      //cout<<"deltaRatioUpPU["<<eta<<"] = "<<deltaRatioUpPU[eta]<<endl;
      //cout<<"deltaRatioDownPU["<<eta<<"] = "<<deltaRatioDownPU[eta]<<endl;
    }

  } 
  
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // 5.) Calculate sys Error from Out-of Cone showering simulation (percentage change of full ratio result)
  //cout<<endl;
  
  double deltaRatioUpMC[nEta]      = {0.};
  double deltaRatioDownMC[nEta]    = {0.};
  

  if(MC){

    rootFiles                   = (TString) "scripts/plotsMC/FinalErrorsMC_" + type + (TString) "_" + method + (TString) ".root";  
    TGraphErrors *MCuncertainty = readTGraphErrors(rootFiles,"graph","Graph");
    double       *sysRelMC      = MCuncertainty -> GetY();
  
    // Percentage change is only in one direction, to take this into account keep deltaRatioDownMC = 0

    for(int eta = 0; eta<nEta; eta++){

      deltaRatioUpMC[eta]   = sysRelMC[eta];
      deltaRatioDownMC[eta] = sysRelMC[eta];

      //cout<<"deltaRatioUpMC["<<eta<<"] = "<<deltaRatioUpMC[eta]<<endl;
      //cout<<"deltaRatioDownMC["<<eta<<"] = "<<deltaRatioDownMC[eta]<<endl;
    }

  } 
  
  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // Take all systematic Uncertainties together and plot
  //cout<<endl;

  double *deltaTotalSysUp   = new double[nEta];
  double *deltaTotalSysDown = new double[nEta];
  double *DeltaTotalSysUp   = new double[nEta];
  double *DeltaTotalSysDown = new double[nEta];
  double *DeltaTotalDown = new double[nEta];
  double *DeltaTotalUp = new double[nEta];
  for(int eta = 0; eta<nEta; eta++){

    // Add all systematic Uncertainties in quadrature (delta is relative Uncertainty)
    deltaTotalSysUp[eta]   = sqrt(TMath::Power(deltaRatioUpJEC[eta],2)   + TMath::Power(deltaRatioUpFlavor[eta],2)   + TMath::Power(deltaRatioUpPU[eta],2)   +                                                               TMath::Power(deltaRatioUpMC[eta],2)    + TMath::Power(deltaRatioUpQCD[eta],2));
    deltaTotalSysDown[eta] = sqrt(TMath::Power(deltaRatioDownJEC[eta],2) + TMath::Power(deltaRatioDownFlavor[eta],2) + TMath::Power(deltaRatioDownPU[eta],2) +                                                               TMath::Power(deltaRatioDownMC[eta],2)  + TMath::Power(deltaRatioDownQCD[eta],2));

    // Calculation of the absolute Uncertainty with Delta = ratio * delta
    DeltaTotalSysUp[eta]   = deltaTotalSysUp[eta] * ratioEtaBinnedY[eta];
    DeltaTotalSysDown[eta] = deltaTotalSysDown[eta] * ratioEtaBinnedY[eta];

    // Calculate Systematic plus staistical Uncertainty
    DeltaTotalUp[eta] = sqrt(pow(DeltaTotalSysUp[eta],2) + pow(ratioEtaBinnedEY[eta],2));
    DeltaTotalDown[eta] = sqrt(pow(DeltaTotalSysDown[eta],2) + pow(ratioEtaBinnedEY[eta],2));

    cout<<endl<<"relative: deltaTotalSysUp["<<eta<<"]   = "<<fixed<<setprecision(3)<<deltaTotalSysUp[eta]<<endl;
    cout<<"relative: deltaTotalSysDown["<<eta<<"] = "<<deltaTotalSysDown[eta]<<endl;

    cout<<endl<<"absolute: DeltaTotalSysUp["<<eta<<"]   = "<<DeltaTotalSysUp[eta]<<endl;
    cout<<"absolute: DeltaTotalSysDown["<<eta<<"] = "<<DeltaTotalSysDown[eta]<<endl;


  }

  double ex[nEta] ={0.25,0.3,0.3,0.3};

  TGraphAsymmErrors* ratioEtaBinnedSys = new TGraphAsymmErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ex,ex,DeltaTotalSysDown,DeltaTotalSysUp);

  double *TotalSysUp   = new double[nEta];
  double *TotalSysDown = new double[nEta];
 

  for(int i=0; i<nEta; i++){
    TotalSysUp[i]   = ratioEtaBinnedY[i]+DeltaTotalSysUp[i];
    TotalSysDown[i] = ratioEtaBinnedY[i]-DeltaTotalSysDown[i];
  }

  TGraph* ratioSysBorderUp   = new TGraph(nEta, ratioEtaBinnedX, TotalSysUp);
  TGraph* ratioSysBorderDown = new TGraph(nEta, ratioEtaBinnedX, TotalSysDown);

  TGraph* ratioRelativeErrorsUp   = new TGraph(nEta,ratioEtaBinnedX,deltaTotalSysUp);
  TGraph* ratioRelativeErrorsDown = new TGraph(nEta,ratioEtaBinnedX,deltaTotalSysDown);


  TGraphErrors* ratioEtaBinnedStat = new TGraphErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ratioEtaBinnedEX,ratioEtaBinnedEY);
  TGraphAsymmErrors* ratioEtaBinnedStatPlusSys = new TGraphAsymmErrors(nEta,ratioEtaBinnedX,ratioEtaBinnedY,ex,ex,DeltaTotalDown,DeltaTotalUp);
  
  TCanvas *cFinal = new TCanvas("cFinal","cFinal",200,10,500,500);
  cFinal -> cd();  
  
  ratioEtaBinnedSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  ratioEtaBinnedSys -> GetXaxis() -> SetTitle("|#eta|");

  if(PU  && flavor  && JEC  && MC && QCD)    etaString  = "All sys. Uncertainties";
  else if(PU  && !flavor && !JEC && !MC && !QCD)  etaString = "Only PU uncert.";
  else if(!PU && flavor  && !JEC && !MC && !QCD)  etaString = "Only flavor uncert.";
  else if(!PU && !flavor && JEC  && !MC && !QCD)  etaString = "Only JEC uncert.";
  else if(!PU && !flavor && !JEC && MC && !QCD)   etaString = "Only Out-of-Cone sim. uncert.";
  else if(!PU && !flavor && !JEC && MC && !QCD)   etaString = "Only Out-of-Cone sim. uncert.";
  else if(!PU && !flavor && !JEC && !MC && QCD)   etaString = "Only QCD uncert.";
  else if(PU && flavor && JEC && !MC && QCD)      etaString = "All besides MC uncertainty.";
  else etaString = "Strange set of systematic uncertainties.";
  cout<<endl<<etaString<<endl<<endl;
  
  ratioEtaBinnedSys -> SetMarkerStyle(20);
  ratioEtaBinnedSys -> SetMarkerSize(1.4);
  ratioEtaBinnedSys -> SetFillColor(kGray);
  ratioEtaBinnedSys -> SetFillStyle(3001);
  ratioEtaBinnedSys -> SetLineColor(kGray);
  ratioEtaBinnedSys -> SetMinimum(0.8);
  ratioEtaBinnedSys -> SetMaximum(1.5);
  ratioEtaBinnedSys -> GetXaxis() -> SetLimits(0., 2.3);
  ratioEtaBinnedSys -> GetXaxis() -> SetNdivisions(6,6,0, "X");
  ratioEtaBinnedSys -> DrawClone("Ae3p");
  
  //ratioEtaBinnedSys -> SetPointError(0, 0., 0., 0., 0.);
  //ratioEtaBinnedSys -> SetPointError(1, 0., 0., 0., 0.);
  //ratioEtaBinnedSys -> SetPointError(2, 0., 0., 0., 0.);
  //ratioEtaBinnedSys -> SetPointError(3, 0., 0., 0., 0.);
  //ratioEtaBinnedSys -> SetPointError(4, 0., 0., 0., 0.);


  ratioEtaBinnedStat -> SetMarkerStyle(20);
  ratioEtaBinnedStat -> SetMarkerSize(1.4);
  ratioEtaBinnedStat -> SetFillColor(kGray);
  ratioEtaBinnedStat -> SetFillStyle(3001);
  ratioEtaBinnedStat -> SetLineColor(1);
  ratioEtaBinnedStat -> Draw("psame");
  
 
  TLatex *infoFinal   = new TLatex();
  infoFinal -> SetTextFont(132);
  infoFinal -> SetNDC();
  infoFinal -> SetTextSize(0.045);
  infoFinal -> DrawLatex(0.2,0.8,etaString);

  filename = (TString) "plots/FinalErrorPlot_" + type + (TString) "_" + method + (TString) ".pdf";
  cFinal -> Print(filename,"pdf");
  filename = (TString) "plots/FinalErrorPlot_" + type + (TString) "_" + method + (TString) ".pdf";
  cFinal -> SaveAs(filename,"pdf");
  delete cFinal;


  filename = (TString) "plots/FinalRelativeErrorsUp_" + type + (TString) "_" + method + (TString) ".root"; 
  f = new TFile(filename,"RECREATE");
  f -> WriteTObject(ratioRelativeErrorsUp,"graph");
  f->Close();
  delete f;
  filename = (TString) "plots/FinalRelativeErrorsLow_" + type + (TString) "_" + method + (TString) ".root"; 
  f = new TFile(filename,"RECREATE");
  f -> WriteTObject(ratioRelativeErrorsDown,"graph");
  f->Close();
  delete f;

  
  ofstream RelativeErrors;
  RelativeErrors.open("plots/Errors.txt");
  
  RelativeErrors<<"Relative Errors: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<fixed<<setprecision(3)<<(deltaTotalSysDown[i]*100)<<"% / +"<<(deltaTotalSysUp[i]*100)<<"%"<<endl;
  }

  RelativeErrors<<endl<<"Absolute Errors: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(DeltaTotalSysDown[i])<<" / +"<<(DeltaTotalSysUp[i])<<endl;
  }

  RelativeErrors<<endl<<endl<<"Relative Errors JEC: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownJEC[i]*100)<<"% / +"<<(deltaRatioUpJEC[i]*100)<<"%"<<endl;
  }
  RelativeErrors<<endl<<endl<<"Relative Errors Flavor: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownFlavor[i]*100)<<"% / +"<<(deltaRatioUpFlavor[i]*100)<<"%"<<endl;
  }
  RelativeErrors<<endl<<endl<<"Relative Errors Out-of-Cone showering simulation: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownMC[i]*100)<<"% / +"<<(deltaRatioUpMC[i]*100)<<"%"<<endl;
  }
  RelativeErrors<<endl<<endl<<"Relative Errors QCD: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownQCD[i]*100)<<"% / +"<<(deltaRatioUpQCD[i]*100)<<"%"<<endl;
  }
  RelativeErrors<<endl<<endl<<"Relative Errors PU reweighing: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(deltaRatioDownPU[i]*100)<<"% / +"<<(deltaRatioUpPU[i]*100)<<"%"<<endl;
  }

  RelativeErrors<<endl<<endl<<"Central values and statistical Uncertainty: "<<endl;
  for(int i=0; i<nEta; i++){
    RelativeErrors<<i+1<<". Eta bin:    "<<"-"<<(ratioEtaBinnedY[i])<<" +/- "<<ratioEtaBinnedEY[i]<<endl;
  }

  RelativeErrors.close();

 
  // Write directly full latex table with systematic and statistical unceratinty

  ofstream latexTable;
  latexTable.open("plots/latexTable.txt");


  latexTable<<"\\renewcommand{\\arraystretch}{2.0}"<<endl;
  latexTable<<"\\begin{center}"<<endl;
  latexTable<<"\\begin{tabular}{ | c | c   c c| }"<<endl;
  latexTable<<"$|\\eta^{\\text{Jet}}|$ & Ratio &  stat.      & sys.  \\\\\\hline"<<endl;
  for(int z=0;z<nEta;z++){
    latexTable<<"$"<<fixed<<setprecision(1)<<etaBins[z]<<" - "<<etaBins[z+1]<<"$ &"<<fixed<<setprecision(3)<<ratioEtaBinnedY[z]<<" & $\\pm "<<ratioEtaBinnedEY[z]<<"$ & $^{+"<<DeltaTotalSysUp[z]<<"}_{-"<<DeltaTotalSysDown[z]<<"}$ \\\\"<<endl;
  }
  latexTable<<"\\hline"<<endl;
  latexTable<<"\\end{tabular}"<<endl;
  latexTable<<"\\end{center}"<<endl<<endl<<endl<<endl<<endl;

 


  
  latexTable<<"\\begin{center}"<<endl;
  latexTable<<"\\begin{tabular}{ l| c | c | c | c |}"<<endl;
  latexTable<<"\\multicolumn{1}{c}{} & \\multicolumn{4}{c}{$|\\eta^{\\text{Jet}}|$}\\\\\\hline"<<endl<<fixed<<setprecision(1);
  for(int z=0;z<nEta;z++) latexTable<<"& \\textbf{"<<etaBins[z]<<" - "<<etaBins[z+1]<<"}";
  latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{Multijet contamination}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpQCD[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaRatioDownQCD[z]*100<<" \\% $ ";
  latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{Flavor uncertainty}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpFlavor[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownFlavor[z]*100<<" \\% $ ";
latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{JEC uncertainty}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpJEC[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownJEC[z]*100<<" \\% $ ";
latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{Out-of-Cone showering simulation}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpMC[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaRatioDownMC[z]*100<<" \\% $ ";
  latexTable<<"\\\\\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{PU uncertainty}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaRatioUpPU[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $"<<deltaRatioDownPU[z]*100<<" \\% $ ";
  latexTable<<"\\\\\\hline\\hline"<<endl;
  latexTable<<"\\multirow{2}{*}{\\textbf{Total}}";
  for(int z=0;z<nEta;z++) latexTable<<"& $+"<<deltaTotalSysUp[z]*100<<" \\% $ ";
  latexTable<<"\\\\"<<endl;
  for(int z=0;z<nEta;z++) latexTable<<"& $-"<<deltaTotalSysDown[z]*100<<" \\% $ ";
  latexTable<<"\\\\\\hline"<<endl;

  latexTable<<"\\end{tabular}"<<endl;
  latexTable<<"\\end{center}"<<endl;


 latexTable.close();





  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  // Comparison to 2011 Data 
  cout<<endl; 

  gROOT->LoadMacro("tdrstyle_mod14.C");
  setTDRStyle();

  gROOT->LoadMacro("CMS_lumi.C");

  writeExtraText = true;       // if extra text
  extraText  = "Preliminary";  // default extra text is "Preliminary"
  lumi_8TeV  = "19.7 fb^{-1}"; // default is "19.7 fb^{-1}"
  lumi_7TeV  = "4.9 fb^{-1}";  // default is "5.1 fb^{-1}"

  int iPeriod = 2;    // 1=7TeV, 2=8TeV, 3=7+8TeV, 7=7+8+13TeV 
  
  gStyle->SetHatchesLineWidth(1);
  gStyle->SetHatchesSpacing(2.2);   
  //-----------------------------------------------------

  TCanvas *cFinal2 = new TCanvas("cFinal2","cFinal2",200,10,1000,1000);
  cFinal2 -> cd();  

  double x_2011[4];
  x_2011[0]=0.25;
  x_2011[1]=0.80;
  x_2011[2]=1.40;
  x_2011[3]=2.00;
  double y_2011[4];
  y_2011[0]=1.052;
  y_2011[1]=1.057;
  y_2011[2]=1.096;
  y_2011[3]=1.134;
  double yErrStat_2011[4];
  yErrStat_2011[0]=0.012;
  yErrStat_2011[1]=0.012;
  yErrStat_2011[2]=0.017;
  yErrStat_2011[3]=0.035;
  double yErrSysHigh_2011[4];
  yErrSysHigh_2011[0]=0.062;
  yErrSysHigh_2011[1]=0.056;
  yErrSysHigh_2011[2]=0.063;
  yErrSysHigh_2011[3]=0.087;
  double yErrSysLow_2011[4];
  yErrSysLow_2011[0]=0.061;
  yErrSysLow_2011[1]=0.055;
  yErrSysLow_2011[2]=0.062;
  yErrSysLow_2011[3]=0.085;
  double xErrLow_2011[4];
  xErrLow_2011[0]=0.25;
  xErrLow_2011[1]=0.3;
  xErrLow_2011[2]=0.3;
  xErrLow_2011[3]=0.3;
  double xErrHigh_2011[4];
  xErrHigh_2011[0]=0.25;
  xErrHigh_2011[1]=0.3;
  xErrHigh_2011[2]=0.3;
  xErrHigh_2011[3]=0.3;

  double yErrTotalHigh_2011[4];
  double yErrTotalLow_2011[4];

  for(int i=0; i<4; i++){

    yErrTotalHigh_2011[i]=sqrt(pow(yErrStat_2011[i],2) + pow(yErrSysHigh_2011[i],2));
    yErrTotalLow_2011[i]=sqrt(pow(yErrStat_2011[i],2) + pow(yErrSysLow_2011[i],2));


  }

  TGraphAsymmErrors *Res_2011_stat = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrStat_2011,yErrStat_2011);
  Res_2011_stat->SetName("Res_2011_stat");
  TGraphAsymmErrors *Res_2011_sys  = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrSysLow_2011,yErrSysHigh_2011);
  Res_2011_sys->SetName("Res_2011_sys");
  TGraphAsymmErrors *Res_2011_total  = new TGraphAsymmErrors(4,x_2011,y_2011,xErrLow_2011,xErrHigh_2011,yErrTotalLow_2011,yErrTotalHigh_2011);
  Res_2011_sys->SetName("Res_2011_total");
  
  //-----------------------------------------------------
  ratioEtaBinnedStatPlusSys -> GetXaxis() -> SetTitle("|#eta|");
  ratioEtaBinnedStatPlusSys -> GetXaxis() -> SetRangeUser(0., 2.3);
  ratioEtaBinnedStatPlusSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  ratioEtaBinnedSys -> GetXaxis() -> SetTitle("|#eta|");
  ratioEtaBinnedSys -> GetXaxis() -> SetRangeUser(0., 2.3);
  ratioEtaBinnedSys -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  ratioEtaBinnedStat -> GetXaxis() -> SetTitle("|#eta|");
  ratioEtaBinnedStat -> GetXaxis() -> SetRangeUser(0., 2.3);
  ratioEtaBinnedStat -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  ratioEtaBinnedStat -> GetYaxis() -> SetRangeUser(0.8, 1.6);
  Res_2011_stat -> GetXaxis() -> SetTitle("|#eta|");
  Res_2011_stat -> GetXaxis() -> SetLimits(0., 2.3);
  Res_2011_stat -> GetXaxis() -> SetNdivisions(505, "X");
  Res_2011_stat -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  Res_2011_sys -> GetXaxis() -> SetTitle("|#eta|");
  Res_2011_sys -> GetXaxis() -> SetLimits(0., 2.3);
  Res_2011_sys -> GetXaxis() -> SetNdivisions(505, "X");
  Res_2011_sys -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  Res_2011_total -> GetXaxis() -> SetTitle("|#eta|");
  Res_2011_total -> GetXaxis() -> SetLimits(0., 2.3);
  Res_2011_total -> GetXaxis() -> SetNdivisions(505, "X");
  Res_2011_total -> GetYaxis() -> SetTitle("Data/MC ratio for JER");
  Res_2011_total -> GetYaxis() -> SetRangeUser(0.8, 1.5);


  ratioEtaBinnedStatPlusSys -> SetMarkerStyle(20); 
  ratioEtaBinnedStatPlusSys -> SetMarkerSize(2.0);
  ratioEtaBinnedStatPlusSys -> SetLineColor(kPink-8);
  ratioEtaBinnedStatPlusSys -> SetLineWidth(2);
  ratioEtaBinnedStatPlusSys -> SetMarkerColor(kPink-8);
  ratioEtaBinnedStatPlusSys -> SetFillColor(kPink-8);
  ratioEtaBinnedStatPlusSys -> SetName("statPlusSys_2012");
  
  ratioEtaBinnedStat -> SetMarkerStyle(20); 
  ratioEtaBinnedStat -> SetMarkerSize(2.0);
  ratioEtaBinnedStat -> SetLineColor(kPink-8);
  ratioEtaBinnedStat -> SetLineWidth(2);
  ratioEtaBinnedStat -> SetMarkerColor(kPink-8);
  ratioEtaBinnedStat -> SetFillColor(kPink-8);
  ratioEtaBinnedStat -> SetName("Stat_2012");

  ratioEtaBinnedStatPlusSys -> SetFillStyle(3244);
  ratioEtaBinnedStat        -> SetFillStyle(3144);

  Res_2011_stat->SetMarkerStyle(24);
  Res_2011_stat->SetMarkerSize(2.0);
  Res_2011_stat->SetLineColor(kGray+2);
  Res_2011_stat->SetLineWidth(2);
  Res_2011_stat->SetLineWidth(2);
  Res_2011_stat->SetFillStyle(1001);

  Res_2011_total->SetMarkerStyle(24);
  Res_2011_total->SetMarkerSize(2.0);
  Res_2011_total->SetLineColor(1);
  Res_2011_total->SetLineWidth(2);
  Res_2011_total->SetFillColor(kGray);
  Res_2011_total->SetFillStyle(1001);
  Res_2011_total->SetLineColor(kGray+2);

  Res_2011_total->Draw("a2");
  Res_2011_stat->Draw("esame");
  
  ratioEtaBinnedStatPlusSys -> Draw("2same");
  Res_2011_stat->Draw("pXsame");
  Res_2011_stat->SetMarkerSize(1.9);
  Res_2011_stat->Draw("pXsame");
  Res_2011_stat->SetMarkerSize(1.7);
  Res_2011_stat->Draw("pXsame");
  ratioEtaBinnedStatPlusSys -> Draw("pXsame");
  ratioEtaBinnedStat        -> Draw("esame");
  
  TLegend *leg = new TLegend(0.18, 0.60, 0.55, 0.75);
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  leg->SetFillStyle(0);
  leg->SetTextFont(42);
  leg->SetTextSize(0.045);
  
  leg->AddEntry(Res_2011_total,"5/fb (7 TeV)", "pfl");
  leg->AddEntry(ratioEtaBinnedStatPlusSys,"20/fb (8 TeV)", "pfl");
     
  leg->Draw("same");

  TLatex *info = new TLatex();
  info->SetNDC();
  info->DrawLatex(0.67,0.83,"Anti-k_{T} R=0.5");
  info->DrawLatex(0.67,0.77,"PF+CHS");

  CMS_lumi( cFinal2, iPeriod, 11 );
  cFinal2->Print("plots/resultsComparisonFINAL.pdf","pdf");
  cFinal2->SaveAs("plots/resultsComparisonFINAL.C");


  return 0;

}
示例#11
0
文件: softrad.C 项目: cihar29/jecsys
// Soft radiation corrections for L3Res
void softrad(double etamin=0.0, double etamax=1.3, bool dodijet=false) {

  setTDRStyle();
  writeExtraText = false; // for JEC paper CWR

  TDirectory *curdir = gDirectory;

  // Open jecdata.root produced by reprocess.C
  TFile *fin = new TFile("rootfiles/jecdata.root","UPDATE");
  assert(fin && !fin->IsZombie());
  
  const int ntypes = 3;
  const char* types[ntypes] = {"data", "mc", "ratio"};
  const int nmethods = 2;
  const char* methods[nmethods] = {"mpfchs1", "ptchs"};
  const int nsamples = (dodijet ? 4 : 3);
  const char* samples[4] = {"gamjet", "zeejet", "zmmjet", "dijet"};
  string sbin = Form("eta%02.0f-%02.0f",10*etamin,10*etamax);
  const char* bin = sbin.c_str();
  const int nalphas = 4;
  const int alphas[nalphas] = {30, 20, 15, 10};

  // Z+jet bins
  const double ptbins1[] = {30, 40, 50, 60, 75, 95, 125, 180, 300, 1000};
  const int npt1 = sizeof(ptbins1)/sizeof(ptbins1[0])-1;
  TH1D *hpt1 = new TH1D("hpt1","",npt1,&ptbins1[0]);
  TProfile *ppt1 = new TProfile("ppt1","",npt1,&ptbins1[0]);

  // gamma+jet bins
  const double ptbins2[] = {30, 40, 50, 60, 75, 100, 125, 155, 180,
			    210, 250, 300, 350, 400, 500, 600, 800};
  const int npt2 = sizeof(ptbins2)/sizeof(ptbins2[0])-1;
  TH1D *hpt2 = new TH1D("hpt2","",npt2,&ptbins2[0]);
  TProfile *ppt2 = new TProfile("ppt2","",npt2,&ptbins2[0]);

  // dijet bins
  const double ptbins4[] = {20, 62, 107, 175, 242, 310, 379, 467,
			    628, 839, 1121, 1497, 2000};
  const int npt4 = sizeof(ptbins4)/sizeof(ptbins4[0])-1;
  TH1D *hpt4 = new TH1D("hpt4","",npt4,&ptbins4[0]);
  TProfile *ppt4 = new TProfile("ppt4","",npt4,&ptbins4[0]);

  TLatex *tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSize(0.045);

  map<string,const char*> texlabel;
  texlabel["gamjet"] = "#gamma+jet";
  texlabel["zeejet"] = "Z#rightarrowee+jet";
  texlabel["zmmjet"] = "Z#rightarrow#mu#mu+jet";
  texlabel["dijet"] = "Dijet";
  texlabel["ptchs"] = "p_{T} balance (CHS)";
  texlabel["mpfchs"] = "MPF raw (CHS)";
  texlabel["mpfchs1"] = "MPF type-I (CHS)";

  // overlay of various alpha values
  TCanvas *c1 = new TCanvas("c1","c1",ntypes*400,nmethods*400);
  c1->Divide(ntypes,nmethods);

  TH1D *h1 = new TH1D("h1",";p_{T} (GeV);Response",1270,30,1300);

  // extrapolation vs alpha for each pT bin
  vector<TCanvas*> c2s(ntypes*nmethods);
  for (unsigned int icanvas = 0; icanvas != c2s.size(); ++icanvas) {
    TCanvas *c2 = new TCanvas(Form("c2_%d",icanvas),Form("c2_%d",icanvas),
			      1200,1200);
    c2->Divide(3,3);
    c2s[icanvas] = c2;
  }

  TH1D *h2 = new TH1D("h2",";#alpha;Response",10,0.,0.4);
  h2->SetMaximum(1.08);
  h2->SetMinimum(0.88);

  // krad corrections
  TCanvas *c3 = new TCanvas("c3","c3",ntypes*400,nmethods*400);
  c3->Divide(ntypes,nmethods);

  TH1D *h3 = new TH1D("h3",";p_{T,ref} (GeV);FSR sensitivity: -dR/d#alpha [%]",
		      1270,30,1300);

  cout << "Reading in data" << endl << flush;
  // Read in plots vs pT (and alpha)
  map<string, map<string, map<string, map<int, TGraphErrors*> > > > gemap;
  map<string, map<string, map<string, map<int, TGraphErrors*> > > > gamap;
  for (int itype = 0; itype != ntypes; ++itype) {
    for (int  imethod = 0; imethod != nmethods; ++imethod) {
      for (int  isample = 0; isample != nsamples; ++isample) {

	for (int  ialpha = 0; ialpha != nalphas; ++ialpha) {

	  fin->cd();
	  assert(gDirectory->cd(types[itype]));
	  assert(gDirectory->cd(bin));
	  TDirectory *d = gDirectory;

	  const char *ct = types[itype];
	  const char *cm = methods[imethod];
	  const char *cs = samples[isample];
	  const int a = alphas[ialpha];
	  // Get graph made vs pT
	  string s = Form("%s/%s/%s_%s_a%d",types[itype],bin,cm,cs,a);
	  TGraphErrors *g = (TGraphErrors*)fin->Get(s.c_str());
	  if (!g) cout << "Missing " << s << endl << flush;
	  assert(g);

	  // Clean out empty points
	  // as well as trigger-biased ones for dijets
	  // as well as weird gamma+jet high pT point
	  for (int i = g->GetN()-1; i != -1; --i) {
	    if (g->GetY()[i]==0 || g->GetEY()[i]==0 ||
		(string(cs)=="dijet" && g->GetX()[i]<70.) ||
		(string(cs)=="gamjet" && g->GetX()[i]>600. && etamin!=0))
	      g->RemovePoint(i);
	  }

	  gemap[ct][cm][cs][a] = g;
	  
	  // Sort points into new graphs vs alpha
	  TH1D *hpt = (isample==0 ? hpt2 : hpt1);
	  TProfile *ppt = (isample==0 ? ppt2 : ppt1);
	  if (isample==3) { hpt = hpt4; ppt = ppt4; } // pas-v6
	  for (int i = 0; i != g->GetN(); ++i) {
	    
	    double pt = g->GetX()[i];
	    ppt->Fill(pt, pt);
	    int ipt = int(hpt->GetBinLowEdge(hpt->FindBin(pt))+0.5);
	    //int ipt = int(pt+0.5);
	    TGraphErrors *ga = gamap[ct][cm][cs][ipt];
	    if (!ga) {
	      ga = new TGraphErrors(0);
	      ga->SetMarkerStyle(g->GetMarkerStyle());
	      ga->SetMarkerColor(g->GetMarkerColor());
	      ga->SetLineColor(g->GetLineColor());
	      gamap[ct][cm][cs][ipt] = ga;
	    }
	    int n = ga->GetN();
	    ga->SetPoint(n, 0.01*a, g->GetY()[i]);
	    ga->SetPointError(n, 0, g->GetEY()[i]);
	  } // for i 

	} // for ialpha

      } // for isample
    } // for imethod
  } // for itype

  cout << "Drawing plots vs pT for each alpha" << endl << flush;

  // 2x6 plots
  for (int itype = 0; itype != ntypes; ++itype) {
    for (int  imethod = 0; imethod != nmethods; ++imethod) {

      const char *ct = types[itype];
      const char *cm = methods[imethod];

      int ipad = ntypes*imethod + itype + 1; assert(ipad<=6);
      c1->cd(ipad);
      gPad->SetLogx();
      h1->SetMaximum(itype<2 ? 1.15 : 1.08);
      h1->SetMinimum(itype<2 ? 0.85 : 0.93);
      h1->SetYTitle(Form("Response (%s)",ct));
      h1->DrawClone("AXIS");
      tex->DrawLatex(0.20,0.85,texlabel[cm]);
      tex->DrawLatex(0.20,0.80,"|#eta| < 1.3, #alpha=0.1--0.3");
      TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90);

      for (int  isample = 0; isample != nsamples; ++isample) {
	for (int  ialpha = 0; ialpha != nalphas; ++ialpha) {

	  const char *cs = samples[isample];
	  const int a = alphas[ialpha];
	  TGraphErrors *g = gemap[ct][cm][cs][a]; assert(g);

	  // Clean out points with very large uncertainty for plot readability
	  for (int i = g->GetN()-1; i != -1; --i) {
	    if (g->GetEY()[i]>0.02) g->RemovePoint(i);
	  }

	  g->Draw("SAME Pz");

	  if (ialpha==0) leg->AddEntry(g,texlabel[cs],"P");
	}
      } // for isample

      // Individual plots for JEC paper
      if ( true ) { // paper

	TH1D *h = new TH1D(Form("h_5%s_%s",ct,cm),
			   Form(";p_{T} (GeV);Response (%s)",ct),
			   1270,30,1300);
	h->GetXaxis()->SetMoreLogLabels();
	h->GetXaxis()->SetNoExponent();
	h->SetMinimum(0.88);
	h->SetMaximum(1.13);

	writeExtraText = true;
	extraText = (string(ct)=="mc" ? "Simulation" : "");
	lumi_8TeV = (string(ct)=="mc" ? "" : "19.7 fb^{-1}");
	TCanvas *c0 = tdrCanvas(Form("c0_%s_%s",cm,ct), h, 2, 11, true);
	c0->SetLogx();
	

	TLegend *leg = tdrLeg(0.55,0.68,0.85,0.83);
	tex->DrawLatex(0.55,0.85,texlabel[cm]);
	tex->DrawLatex(0.55,0.18,"|#eta| < 1.3, #alpha=0.3");
	//tex->DrawLatex(0.55,0.18,"Anti-k_{T} R=0.5");

	// Loop over Z+jet and gamma+jet (only, no dijet/multijet)
	for (int  isample = 0; isample != min(3,nsamples); ++isample) {
	  
	  const char *cs = samples[isample];
	  TGraphErrors *g = gemap[ct][cm][cs][30]; assert(g);
	  g->Draw("SAME Pz");
	  
	  leg->AddEntry(g,texlabel[cs],"P");
	} // for isample

	if (etamin==0) {
	  c0->SaveAs(Form("pdf/paper_softrad_%s_%s_vspt.pdf",ct,cm));
	  c0->SaveAs(Form("pdfC/paper_softrad_%s_%s_vspt.C",ct,cm));
	}
	else {
	  c0->SaveAs(Form("pdf/an_softrad_%s_%s_eta%1.0f-%1.0f_vspt.pdf",
			  ct,cm,10*etamin,10*etamax));
	}
      } // paper

    } // for imethod
  } // for itype
  
  c1->cd(0);
  //cmsPrel(_lumi, true);
  CMS_lumi(c1, 2, 33);
  c1->SaveAs("pdf/softrad_2x6_vspt.pdf");


  cout << "Drawing plots vs alpha for each pT" << endl << flush;
  cout << "...and fitting slope vs alpha" << endl << flush;

  map<string, map<string, map<string, TGraphErrors* > > > gkmap;

  // 2x6 plots
  for (int itype = 0; itype != ntypes; ++itype) {
    for (int  imethod = 0; imethod != nmethods; ++imethod) {
      
      int icanvas = nmethods*imethod + itype; assert(icanvas<=6);
      TCanvas *c2 = c2s[icanvas]; assert(c2);

      const char *ct = types[itype];
      const char *cm = methods[imethod];

      const int npads = 9;
      for (int ipad = 0; ipad != npads; ++ipad) {
	c2->cd(ipad+1);
	h2->SetYTitle(Form("Response (%s)",ct));
	h2->DrawClone("AXIS");
	tex->DrawLatex(0.20,0.85,texlabel[cm]);
	tex->DrawLatex(0.20,0.80,"|#eta| < 1.3");
	tex->DrawLatex(0.20,0.75,Form("%1.0f < p_{T} < %1.0f GeV",
				      hpt1->GetBinLowEdge(ipad+1),
				      hpt1->GetBinLowEdge(ipad+2)));
	TLegend *leg = tdrLeg(0.65,0.75,0.90,0.90);
	leg->AddEntry(gemap[ct][cm]["gamjet"][30], texlabel["gamjet"], "P");
	leg->AddEntry(gemap[ct][cm]["zeejet"][30], texlabel["zeejet"], "P");
	leg->AddEntry(gemap[ct][cm]["zmmjet"][30], texlabel["zmmjet"], "P");
	leg->AddEntry(gemap[ct][cm]["dijet"][30], texlabel["dijet"], "P");
      }

      for (int  isample = 0; isample != nsamples; ++isample) {

	const char *cs = samples[isample];

	map<int, TGraphErrors*> &gam = gamap[ct][cm][cs];
	map<int, TGraphErrors*>::iterator itpt;
	for (itpt = gam.begin(); itpt != gam.end(); ++itpt) {

	  int ipt = itpt->first;
	  int jpt = hpt1->FindBin(ipt);
	  if (jpt>npads) continue;
	  assert(jpt<=npads);
	  c2->cd(jpt);
	  
	  TGraphErrors *ga = itpt->second; assert(ga);
	  
	  ga->Draw("SAME Pz");

	  // Fit slope
	  TF1 *f1 = new TF1(Form("f1_%s_%s_%s_%d",ct,cm,cs,ipt),
			    "(x<1)*([0]+[1]*x) + (x>1 && x<2)*[0] +"
			    "(x>2)*[1]",-1,1);
	  f1->SetLineColor(ga->GetLineColor());
	  f1->SetParameters(1,0);
	  const double minalpha = (isample==0 ? 10./ipt : 5./ipt);
	  // Constrain slope to within reasonable values
	  // in the absence of sufficient data using priors
	  if (true) { // use priors
	    int n = ga->GetN();
	    // For response, limit to 1+/-0.02 (we've corrected for L3Res
	    ga->SetPoint(n, 1.5, 1);
	    ga->SetPointError(n, 0, 0.02);
	    n = ga->GetN();
	    if (imethod==1) { // pT balance
	      // For pT balance, estimate slope of <vecpT2>/alpha from data
	      // => 7.5%/0.30 = 25%
	      // Approximate uncertainty on this to be
	      // 0.5%/0.30 ~ 1.5% for data, 0.5%/0.30 ~ 1.5% for Z+jet MC, and
	      // 2%/0.30 ~ 6% for gamma+jet MC (same as slope)
	      if (itype==0)               ga->SetPoint(n, 2.5, -0.250); // DT
	      if (itype==1 && isample!=0) ga->SetPoint(n, 2.5, -0.250); // MC
	      if (itype==1 && isample==0) ga->SetPoint(n, 2.5, -0.190);
	      if (itype==2 && isample!=0) ga->SetPoint(n, 2.5, -0.000); // rt
	      if (itype==2 && isample==0) ga->SetPoint(n, 2.5, -0.060); 
	      //
	      // BUG: found 2015-01-08 (no effect on ratio)
	      //if (itype==1)               ga->SetPointError(n, 0, -0.015);
	      if (itype==0)               ga->SetPointError(n, 0, -0.015); // DT
	      if (itype==1 && isample!=0) ga->SetPointError(n, 0, -0.015); // MC
	      if (itype==1 && isample==0) ga->SetPointError(n, 0, -0.060);
	      if (itype==2 && isample!=0) ga->SetPointError(n, 0, -0.015); // rt
	      if (itype==2 && isample==0) ga->SetPointError(n, 0, -0.060); 
	    }
	    if (imethod==0) { // MPF
	      // For MPF, expectation is no slope
	      // Maximal slope would be approximately
	      // (<vecpT2>/alpha ~ 25% from pT balance) times
	      // (response difference between pT1 and vecpT2~10%)
	      // => 0.25*0.10 = 2.5%
	      // For data/MC, estimate uncertainty as half of this
	      // => 1.25%
	      ga->SetPoint(n, 2.5, 0.);
	      if (itype!=2) ga->SetPointError(n, 0, 0.025);
	      if (itype==2) ga->SetPointError(n, 0, 0.0125);
	    } // MPF
	  } // use priors

	  if (ga->GetN()>2) {

	    f1->SetRange(minalpha, 3.);
	    ga->Fit(f1,"QRN");

	    if (f1->GetNDF()>=0) {
	      f1->DrawClone("SAME");
	      f1->SetRange(0,0.4);
	      f1->SetLineStyle(kDashed);
	      f1->DrawClone("SAME");

	      // Store results
	      TGraphErrors *gk = gkmap[ct][cm][cs];
	      if (!gk) {
		gk = new TGraphErrors(0);
		gk->SetMarkerStyle(ga->GetMarkerStyle());
		gk->SetMarkerColor(ga->GetMarkerColor());
		gk->SetLineColor(ga->GetLineColor());
		gkmap[ct][cm][cs] = gk;
	      }
	      int n = gk->GetN();
	      TProfile *ppt = (isample==0 ? ppt2 : ppt1);
	      if (isample==3) { ppt = ppt4; } // pas-v6
	      double pt = ppt->GetBinContent(ppt->FindBin(ipt));
	      gk->SetPoint(n, pt, f1->GetParameter(1));
	      gk->SetPointError(n, 0, f1->GetParError(1));
	    } // f1->GetNDF()>=0
	  } // ga->GetN()>2
	} // for itpt
	
      } // for isample
      
      c2->SaveAs(Form("pdf/softrad_3x3_%s_%s_vsalpha.pdf",ct,cm));
      
    }
  }


  cout << "Drawing plots of kFSR vs pT" << endl;

  // 2x6 plots
  for (int itype = 0; itype != ntypes; ++itype) {
    for (int  imethod = 0; imethod != nmethods; ++imethod) {

      const char *ct = types[itype];
      const char *cm = methods[imethod];

      TMultiGraph *mgk = new TMultiGraph();

      int ipad = ntypes*imethod + itype + 1; assert(ipad<=6);
      c3->cd(ipad);
      gPad->SetLogx();
      h3->SetMaximum(imethod==0 ? 0.05 : (itype!=2 ? 0.1 : 0.25));
      h3->SetMinimum(imethod==0 ? -0.05 : (itype!=2 ? -0.4 : -0.25));
      h3->SetYTitle(Form("k_{FSR} = dR/d#alpha (%s)",ct));
      h3->DrawClone("AXIS");
      tex->DrawLatex(0.20,0.85,texlabel[cm]);
      tex->DrawLatex(0.20,0.80,"|#eta| < 1.3");
      TLegend *leg = tdrLeg(0.60,0.75,0.90,0.90);

      for (int  isample = 0; isample != nsamples; ++isample) {

	const char *cs = samples[isample];
	TGraphErrors *gk = gkmap[ct][cm][cs]; assert(gk);
	
	leg->AddEntry(gk,texlabel[cs],"P");

	// Fit each sample separately for pT balance
	if (true) {

	  TF1 *fk = new TF1(Form("fk_%s_%s_%s",ct,cm,cs),
			    "[0]+[1]*log(0.01*x)+[2]*pow(log(0.01*x),2)",
			    30,1300);
	  fk->SetParameters(-0.25,-0.5);
	  fk->SetLineColor(gk->GetLineColor());
	  gk->Fit(fk, "QRN");

	  tex->SetTextColor(fk->GetLineColor());
	  tex->DrawLatex(0.55,0.27-0.045*isample,
			 Form("#chi^{2}/NDF = %1.1f / %d",
			      fk->GetChisquare(), fk->GetNDF()));
	  tex->SetTextColor(kBlack);

	  // Error band
	  const int n = fk->GetNpar();
	  TMatrixD emat(n,n);
	  gMinuit->mnemat(emat.GetMatrixArray(), n);
	  TF1 *fke = new TF1(Form("fk_%s_%s_%s",ct,cm,cs),
			     sr_fitError, 30, 1300, 1);
	  _sr_fitError_func = fk;
	  _sr_fitError_emat = &emat;

	  fke->SetLineStyle(kSolid);
	  fke->SetLineColor(fk->GetLineColor()-10);
	  fke->SetParameter(0,-1);
	  fke->DrawClone("SAME");
	  fke->SetParameter(0,+1);
	  fke->DrawClone("SAME");

	  fk->DrawClone("SAME");
	  gk->DrawClone("SAME Pz");

	  // Store soft radiation corrections in fsr subdirectory
	  assert(fin->cd(ct));
	  assert(gDirectory->cd(bin));
	  if (!gDirectory->FindObject("fsr")) gDirectory->mkdir("fsr");
	  assert(gDirectory->cd("fsr"));

	  TH1D *hk = (TH1D*)(isample==0 ? hpt2->Clone() : hpt1->Clone());
	  hk->SetName(Form("hkfsr_%s_%s",cm,cs));
	  TProfile *ppt = (isample==0 ? ppt2 : ppt1);
	  if (isample==3) { ppt = ppt4; } // pas-v6
	  for (int i = 1; i != hk->GetNbinsX()+1; ++i) {
	    double pt = ppt->GetBinContent(i);
	    if (pt>30 && pt<1300) {
	      hk->SetBinContent(i, fk->Eval(pt));
	      hk->SetBinError(i, fabs(fke->Eval(pt)-fk->Eval(pt)));
	    }
	    else {
	      hk->SetBinContent(i, 0);
	      hk->SetBinError(i, 0);
	    }
	  }
	  
	  hk->Write(hk->GetName(), TObject::kOverwrite);

	  // Factorize error matrix into eigenvectors
	  // Remember: A = Q*Lambda*Q^-1, where
	  // A is emat, Q is eigmat, and Lambda is a diagonal matrix with
	  // eigenvalues from eigvec on the diagonal. For eigenmatrix
	  // Q^-1 = Q^T, i.e. inverse matrix is the original transposed
	  TVectorD eigvec(n);
	  TMatrixD eigmat = emat.EigenVectors(eigvec);

	  // Eigenvectors are the columns and sum of eigenvectors squared
	  // equals original uncertainty. Calculate histograms from the
	  // eigenvectors and store them
	  TF1 *fkeig = (TF1*)fk->Clone(Form("%s_eig",fk->GetName()));
	  fkeig->SetLineStyle(kDotted);
	  for (int ieig = 0; ieig != n; ++ieig) {

	    // Eigenvector functions
	    for (int i = 0; i != n; ++i) {
	      fkeig->SetParameter(i, fk->GetParameter(i)
				  + eigmat[i][ieig] * sqrt(eigvec[ieig]));
	    }
	    fkeig->DrawClone("SAMEL");

	    // Eigenvector histograms evaluated at bin mean pT
	    TH1D *hke = (TH1D*)hk->Clone(Form("%s_eig%d",hk->GetName(),ieig));
	    hke->Reset();

	    for (int i = 0; i != gk->GetN(); ++i) {

	      double pt = gk->GetX()[i];
	      int ipt = hke->FindBin(pt);
	      // Need to store central value as well, because
	      // uncertainty sources are signed
	      hke->SetBinContent(ipt, fkeig->Eval(pt)-fk->Eval(pt));
	      hke->SetBinError(ipt, fabs(fkeig->Eval(pt)-fk->Eval(pt)));
	    }
	    hke->Write(hke->GetName(), TObject::kOverwrite);
	  }

	  cout << "." << flush;
	} // if tree
      } // for isample
    } // for imethod
  } // for itype
  
  c3->cd(0);
  //cmsPrel(_lumi, true);
  CMS_lumi(c3, 2, 33);
  c3->SaveAs("pdf/softrad_2x6_kfsr.pdf");

  fin->Close();
  curdir->cd();
} // softrad
示例#12
0
文件: drawAvsB.C 项目: miquork/jecsys
// Determine sensitivity to tracker dynamic inefficiency
// by studying ratio of jet responses in Runs G and F (and BCD / F, E / F)
void drawAvsB() {

  setTDRStyle();

  string epocha = "BCD";//"BCD";//"H";//"F";//"BCD";//"F";//"E";//"BCD";//"F";
  string epochb = "GH";//"G";//"BCD";//"G";//"E";//"E";//"F";//"G";

  // Add the rest as well
  string epocha2 = "";//"EF";
  string epochb2 = "";//"G";

  string type = "data";

  vector<string> methods;
  methods.push_back("mpfchs1");
  methods.push_back("ptchs");
  bool nozjptb = false;
  bool nogjmpf = false;
  bool nogjptb = true;
  bool mjvsjes = false;
  
  vector<string> samples;
  samples.push_back("zeejet");
  samples.push_back("zmmjet");
  samples.push_back("gamjet");
  //samples.push_back("multijet");

  cout << "draw"<<epocha<<"vs"<<epochb<<endl;
  const char *ct = type.c_str();
  const char *pa = epocha.c_str();
  const char *pb = epochb.c_str();

  const char *pa2 = epocha2.c_str();
  const char *pb2 = epochb2.c_str();

  TFile *fg = new TFile(Form("rootfiles/jecdata%s.root",pb),"READ");
  assert(fg && !fg->IsZombie());

  TFile *ff = new TFile(Form("rootfiles/jecdata%s.root",pa),"READ");
  assert(ff && !ff->IsZombie());

  TFile *fg2(0), *ff2(0);
  if (epochb2!="") fg2 = new TFile(Form("rootfiles/jecdata%s.root",pb2),"READ");
  if (epocha2!="") ff2 = new TFile(Form("rootfiles/jecdata%s.root",pa2),"READ");

  TH1D *h = new TH1D("h",
		     Form(";p_{T,ref} (GeV);%s ratio (%s / %s)",
			  (type=="ratio" ? "Data/MC" :
			   type=="data" ? "Data/data" : "MC/MC"),
			  (epocha + (epocha2!="" ? "+"+epocha2 : "")).c_str(),
			  (epochb + (epochb2!="" ? "+"+epochb2 : "")).c_str()),
		     3470,30,3500);
  h->SetMinimum(0.90);
  h->SetMaximum(1.15);
  h->GetXaxis()->SetMoreLogLabels();
  h->GetXaxis()->SetNoExponent();

  if (epocha=="F" && epochb=="G")
    lumi_13TeV = "Run2016F+G, 3.1+7.1 fb^{-1}";
  if (epocha=="BCD" && epochb=="G")
    lumi_13TeV = "Run2016BCD+H, 12.9+8.8 fb^{-1}";
  if (epocha=="BCD" && epochb=="G")
    lumi_13TeV = "Run2016BCD+FearlyGH, 12.9+16.8 fb^{-1}";
  if (epocha=="BCD" && epochb=="F")
    lumi_13TeV = "Run2016BCD+F, 13+3.1 fb^{-1}";
  if (epocha=="BCD" && epochb=="E")
    lumi_13TeV = "Run2016BCD+E, 13+4.0 fb^{-1}";
  if (epocha=="E" && epochb=="F")
    lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}";
  if (epocha=="F" && epochb=="E")
    lumi_13TeV = "Run2016E+F, 4.0+3.1 fb^{-1}";

  if ((epocha=="BCDEF" && epochb=="GH") ||
      (epocha=="BCD" && epocha2=="EF" && epochb=="H" && epochb2=="G")) 
    lumi_13TeV = "Run2016BCDEF+GH, 19.7+16.8 fb^{-1}";
  if (epocha=="EF" && epochb=="BCD")
    lumi_13TeV = "Run2016BCD+EF, 12.9+6.8 fb^{-1}";
  if (epocha=="H" && epochb=="G")
    lumi_13TeV = "Run2016G+H, 8.0+8.8 fb^{-1}";

  if ((epocha=="BCD" && epocha2=="EF" && epochb=="G" && epochb2=="H")) 
    lumi_13TeV = "Run2016BCDFearly+FlateGH, 19.7+16.8 fb^{-1}";

  if ((epocha=="BCD" && epocha2=="" && ((epochb=="GH" && epochb2=="") ||
					(epochb=="G" && epochb2=="H"))))
    lumi_13TeV = "Run2016BCD+FlateGH, 12.9+16.8 fb^{-1}";
  if ((epocha=="EF" && epocha2=="" && ((epochb=="GH" && epochb2=="") ||
				       (epochb=="G" && epochb2=="H"))))
    lumi_13TeV = "Run2016EF+FlateGH, 6.8+16.8 fb^{-1}";

  if ((epocha=="EF" && epocha2=="" && epochb=="G" && epochb2=="H")) 
    lumi_13TeV = "Run2016EFearly+FlateGH, 6.8+16.8 fb^{-1}";


  TCanvas *c1 = tdrCanvas("c1",h,4,11,true);
  c1->SetLogx();

  TLatex *tex = new TLatex();
  tex->SetNDC(); tex->SetTextSize(0.045);

  TMultiGraph *mg = new TMultiGraph();
  string s = "draw"+epocha+(epocha2!="" ? "p" + epocha2 : "")
    +"vs"+epochb+(epochb2!="" ? "p" + epochb2 : "");

  TGraphErrors *gmjb(0), *gmpf(0);

  for (unsigned int im = 0; im != methods.size(); ++im) {
    const char *cm = methods[im].c_str();

    tex->DrawLatex(0.20,0.75-0.06*im,cm);
    s += "_" + methods[im];

  for (unsigned int is = 0; is != samples.size(); ++is) {

    const char *cs = samples[is].c_str();
    TGraphErrors *gg = (TGraphErrors*)fg->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs));
    cout << cm << " " << cs << endl << flush;
    assert(gg);
    if (fg2) {
      TGraphErrors *gg2 = (TGraphErrors*)fg2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs));
      assert(gg2);
      gg = addGraph(gg,gg2);
    }
    
    TGraphErrors *gf = (TGraphErrors*)ff->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs));
    assert(gf);
    if (ff2) {
      TGraphErrors *gf2 = (TGraphErrors*)ff2->Get(Form("%s/eta00-13/%s_%s_a30",ct,cm,cs));
      assert(gf2);
      gf = addGraph(gf,gf2);
    }
    
    if (!(gf->GetN()==gg->GetN())) {

      // Remove highest pT point is that is the offender (BCD vs GH)
      if (gg->GetN()>gf->GetN() &&
	  fabs(gg->GetX()[gg->GetN()-1]/gf->GetX()[gf->GetN()-1]-1)>0.1 &&
	  fabs(gg->GetX()[gg->GetN()-2]/gf->GetX()[gf->GetN()-1]-1)<0.1) {
	cout << "Remove point B(N-1)" << endl;
	gg->RemovePoint(gg->GetN()-1);
      }
      else {
	cout << "sample " << samples[is] << " method " << methods[im]
	     << " gf->N: " << gf->GetN() << " gg->N: " << gg->GetN() << endl;
	cout << " x_gf(N-1)=" << gf->GetX()[gf->GetN()-1]
	     << " x_gg(N-1)=" << gg->GetX()[gg->GetN()-1]
	     << " x_gg(N-2)=" << gg->GetX()[gg->GetN()-2] << endl;
      }

      assert(gf->GetN()==gg->GetN());
    }

    TGraphErrors *g = (TGraphErrors*)gg->Clone(Form("ge_%s_%s",cm,cs));
    for (int i = 0; i != g->GetN(); ++i) {
      double yg = gg->GetY()[i];
      double yf = gf->GetY()[i];
      g->SetPoint(i, gg->GetX()[i], yf / yg);
      double ex = gg->GetEX()[i];
      double eg = gg->GetEY()[i];
      double ef = gf->GetEY()[i];
      g->SetPointError(i, ex, yf/yg*sqrt(pow(eg/yg,2)+pow(ef/yf,2)));
    }
    //g->Draw(is==0 ? "AP" : "SAMEP");
    g->SetLineWidth(1+is);
    g->Draw("SAMEPZ");

    if (samples[is]=="gamjet" && methods[im]=="mpfchs1" && nogjmpf) {
      tex->SetTextColor(kBlue);
      tex->DrawLatex(0.20,0.63,"#gamma+jet MPF excl. from fit");
      tex->SetTextColor(kBlack);
    }
    else if (samples[is]=="gamjet" && methods[im]=="ptchs" && nogjptb) {
      tex->SetTextColor(kBlue);
      tex->DrawLatex(0.20,0.63,"#gamma+jet p_{T}^{bal} excl. from fit");
      tex->SetTextColor(kBlack);
    }
    else if ((samples[is]=="zmmjet" || samples[is]=="zeejet") &&
	     methods[im]=="ptchs" && nozjptb) {
      tex->SetTextColor(kRed);
      tex->DrawLatex(0.20,0.63,"Z+jet p_{T}^{bal} excl. from fit");
      tex->SetTextColor(kBlack);
    }
    else if (samples[is]=="multijet") {
      g->SetMarkerColor(kGray+1);
      g->SetLineColor(kGray+1);
      if (methods[im]=="ptchs") gmjb = g;
      if (methods[im]=="mpfchs1") gmpf = g;
    }
    else
      mg->Add(g);
  } // for is
  } // for im
  
  if (nogjmpf) s += "_nogjmpf";
  if (nogjptb) s += "_nogptb";
  if (nozjptb) s += "_nozptb";
  if (mjvsjes) {
    s += "_mjvsjes";
    tex->SetTextColor(kBlack);
    tex->DrawLatex(0.20,0.58,"Multijet vs JES fit");
  }

  TF1 *fjes = new TF1("fjes",jesFit,30,2200,2);
  fjes->SetParameters(0.99,0.05);
  mg->Fit(fjes,"RN");
  fjes->SetLineColor(kBlack);
  fjes->SetLineStyle(kDashed);
  fjes->SetLineWidth(2);
  fjes->SetRange(10.,3500.);
  fjes->Draw("SAME");
  
  //TF1 *ft = new TF1("ft","1-[0]-[1]*pow(x,[2]) + ([3]+[4]*log(x))/x",30,2200);
  //ft->SetParameters(0,0.05,-0.5,1,0.1);
  //ft->FixParameter(3,0);

  // Logarithmic sigmoid
  //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-log(abs([1])))"
  //	       "/(log(abs([2])+abs([1]))-log(abs([1])))))", 30,2200);
  //ft->SetParameters(0.98, 150, 50);
  TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))",30,2200);
  //ft->SetParameters(0.98,log(145),log(190)-log(145));
  //ft->SetParameters(0.982,4.967,0.271);
  //ft->SetParameters(0.976,5.040,0.370); // ENDCAP
  //ft->SetParameters(0.985,5.0,0.3);
  ft->SetParameters(0.985,5.025,0.3);
  //ft->FixParameter(1,5.03); // semi-weighted average of BCD and EF
  //ft->FixParameter(2,0.395); // combined fit to BCD+EF / G+H 

  // ( 12.9*5.055+6.8*5.000)/(12.9+6.8)
  ft->FixParameter(1,5.036); // semi-weighted average of BCD/GH and EF/GH
  // ( 12.9*0.344 + 6.8*0.455)/(12.9+6.8)
  ft->FixParameter(2,0.391); // combined fit to BCD+EF / GH 

  // Log-sigmoid + powerlaw
  //TF1 *ft = new TF1("ft","[0]+(1-[0])/(1. + exp(-(log(x)-[1])/[2]))"
  //	       "*(1-[3]*pow(x,[4]))",30,2200);
  //ft->SetParameters(0.982,4.967,0.271,0.1,-0.2);
  // Double powerlaw
  //TF1 *ft = new TF1("ft","[4]-[0]*pow(x,[1])-[2]*pow(x,[3])",30,2200);
  //ft->SetParameters(0.05,-0.15,0.01,-0.3,1);
  

  mg->Fit(ft,"RN");
  ft->SetLineColor(kBlue);
  ft->SetLineWidth(2);
  ft->SetRange(10.,3500.);
  ft->Draw("SAME");

  // Map multijet with response ratio
  if (gmpf) { // we have multijet available
    TGraphErrors *gmpf2 = (TGraphErrors*)gmpf->Clone("gmpf2");
    gmpf2->SetMarkerColor(kBlack);//kGray+1);
    gmpf2->SetLineColor(kBlack);//kGray+1);
    for (int i = 0; i != gmpf->GetN(); ++i) {
      if (mjvsjes) {
	gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i],
			fjes->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]);
	gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i],
			     gmpf->GetEY()[i]);
      }
      else {
	gmpf2->SetPoint(i, 0.4*gmpf->GetX()[i],
			ft->Eval(gmpf->GetX()[i])/gmpf->GetY()[i]);
	gmpf2->SetPointError(i, 0.4*gmpf->GetEX()[i],
			     gmpf->GetEY()[i]);
      }
    }
    gmpf2->Draw("SAMEPz");
  } // multijet

  tex->SetTextColor(kBlue);
  tex->DrawLatex(0.50,0.85,Form("#chi^{2} / NDF = %1.1f / %d",
				ft->GetChisquare(),
				ft->GetNDF()));
  tex->SetTextColor(kBlack);
  tex->SetTextSize(0.040);
  tex->DrawLatex(0.50,0.80,Form("(#chi^{2} / NDF = %1.1f / %d)",
				fjes->GetChisquare(),
				fjes->GetNDF()));


  tex->SetTextColor(kBlue-9);
  tex->SetTextSize(0.030);
  tex->DrawLatex(0.20,0.25,ft->GetExpFormula());
  tex->DrawLatex(0.20,0.20,
		 Form("p_{0}=%1.3f#pm%1.3f"
		      ", p_{1}=%1.3f#pm%1.3f"
		      ", p_{2}=%1.3f#pm%1.3f",
		      ft->GetParameter(0),ft->GetParError(0),
		      ft->GetParameter(1),ft->GetParError(1),
		      ft->GetParameter(2),ft->GetParError(2)));
  if (ft->GetNpar()>3)
    tex->DrawLatex(0.20,0.17,
		   Form("p_{3}=%1.3f#pm%1.3f"
			", p_{4}=%1.3f#pm%1.3f",
			ft->GetParameter(3),ft->GetParError(3),
			ft->GetParameter(4),ft->GetParError(4)));

  c1->SaveAs(Form("pdf/%s.pdf",s.c_str()));

  for (int i = 0; i != ft->GetNpar(); ++i) {
    cout << Form("%s%1.4g",i==0 ? "{" : ", ",ft->GetParameter(i));
  }
  cout << "}" << endl;
    

}