示例#1
0
void track_start(char const * c) {

  //gStyle->SetOptStat(0);
  
  TFile * file = TFile::Open(c);
  TTree * tree = (TTree*)file->Get("track_start");
  
  TFile * ofile = TFile::Open("track_start_plot.root", "recreate");

  TCanvas * temp = new TCanvas("startdist");
  tree->Draw("startdist>>ht");
  TH1F * h = dynamic_cast<TH1F *>(gDirectory->Get("ht"));
  h->SetTitle("");
  h->GetXaxis()->CenterTitle();
  h->GetXaxis()->SetTitle("Reco - MC Track Start Distance [cm]");
  temp->Write();
  delete temp;
  delete h;

  TCanvas * temp2 = new TCanvas("startdistzoom");
  tree->Draw("startdist>>htt(100, 0, 10)");
  TH1F * h2 = dynamic_cast<TH1F *>(gDirectory->Get("htt"));
  h2->SetTitle("");
  h2->GetXaxis()->CenterTitle();
  h2->GetXaxis()->SetTitle("Reco - MC Track Start Distance [cm]");
  temp2->Write();
  delete temp2;
  delete h2;

  TCanvas * dcx = new TCanvas("trackx");
  tree->Draw("recostartx-truestartx>>hx(100, -5, 5)");
  TH1F * hx = dynamic_cast<TH1F *>(gDirectory->Get("hx"));
  hx->SetTitle("X-axis");
  hx->GetXaxis()->CenterTitle();
  hx->GetXaxis()->SetTitle("Reco - MC Track Start Distance [cm]");
  dcx->Write();
  delete dcx;
  delete hx;

  TCanvas * dcy = new TCanvas("tracky");
  tree->Draw("recostarty-truestarty>>hy(100, -5, 5)");
  TH1F * hy = dynamic_cast<TH1F *>(gDirectory->Get("hy"));
  hy->SetTitle("Y-axis");
  hy->GetXaxis()->CenterTitle();
  hy->GetXaxis()->SetTitle("Reco - MC Track Start Distance [cm]");
  dcy->Write();
  delete dcy;
  delete hy;

  TCanvas * dcz = new TCanvas("trackz");
  tree->Draw("recostartz-truestartz>>hz(100, -5, 5)");
  TH1F * hz = dynamic_cast<TH1F *>(gDirectory->Get("hz"));
  hz->SetTitle("Z-axis");
  hz->GetXaxis()->CenterTitle();
  hz->GetXaxis()->SetTitle("Reco - MC Track Start Distance [cm]");
  dcz->Write();
  delete dcz;
  delete hz;


  ofile->Close();

}
示例#2
0
void compare_lf(){
  

    gStyle->SetErrorX(0); 
  //outputfile

  TFile* nominalfile=new TFile("~/qcd_dijets/scalefactor_lf_nominal/scalefactor/result.root");
  TFile* HFupfile=new TFile("~/qcd_dijets/scalefactor_lf_HFup/result_HFup.root");
  TFile* HFdownfile=new TFile("~/qcd_dijets/scalefactor_lf_HFdown/result_HFdown.root");
  TFile* JECupfile=new TFile("~/qcd_dijets/JEC-uncertainty/JEC_up/scalefactor_lf_JECup/scalefactor_JECup/result_JECup.root");
  TFile* JECdownfile=new TFile("~/qcd_dijets/JEC-uncertainty/JEC_down/scalefactor_lf_JECdown/scalefactor_JECdown/result_JECdown.root");

  int n_ptbins=10;
  int n_etabins=4;
  
  TString eta_counter="0";
  TString pt_counter="0";
  
  vector<vector<TH1F*>> nominal;
  nominal.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  vector<vector<TH1F*>> nominaldots;
  nominaldots.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  
  vector<vector<TH1D*>> staterror;
  staterror.resize(n_ptbins, vector<TH1D*>(n_etabins, 0));
  
  vector<vector<TH1F*>> JECup;
  JECup.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  vector<vector<TH1F*>> JECdown;
  JECdown.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  
  vector<vector<TH1F*>> HFup;
  HFup.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  vector<vector<TH1F*>> HFdown;
  HFdown.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  
  vector<vector<TH1F*>> uncover;
  uncover.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  vector<vector<TH1F*>> unclower;
  unclower.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  
  vector<vector<TH1F*>> JECover;
  JECover.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  vector<vector<TH1F*>> JEClower;
  JEClower.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  
  vector<vector<TH1F*>> HFover;
  HFover.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  vector<vector<TH1F*>> HFlower;
  HFlower.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  
  cout << "read histos" << endl;
  for (int i=1; i<n_ptbins;++i){
      if (i==0) pt_counter="0";
      else if (i==1) pt_counter="1";
      else if (i==2) pt_counter="2";
      else if (i==3) pt_counter="3";
      else if (i==4) pt_counter="4";
      else if (i==5) pt_counter="5";
      else if (i==6) pt_counter="6";
      else if (i==7) pt_counter="7";
      else if (i==8) pt_counter="8";
      else if (i==9) pt_counter="9";
      for ( int j=1; j<n_etabins;++j){   
	if (j==0) eta_counter="0";
	else if (j==1) eta_counter="1";
	else if (j==2) eta_counter="2";   
	else if (j==3) eta_counter="3"; 
	TH1F* dots = (TH1F*)nominalfile->Get("clone_diff_lf_ptbin"+pt_counter+"_etabin"+eta_counter);
	nominaldots[i][j]=dots;
	nominaldots[i][j]->SetStats(0);
	
	TH1D* h_stat = (TH1D*)nominalfile->Get("hint_ptbin"+pt_counter+"_etabin"+eta_counter);
	staterror[i][j]=h_stat;
	staterror[i][j]->SetStats(0);
	
	TH1F* hist = (TH1F*)nominalfile->Get("LFSF_pt"+pt_counter+"_eta"+eta_counter);
	nominal[i][j]=hist;
	nominal[i][j]->SetStats(0);
	
	TH1F* h_JECup = (TH1F*)JECupfile->Get("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_JECup");
	JECup[i][j]=h_JECup;
	TH1F* h_JECdown = (TH1F*)JECdownfile->Get("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_JECdown");
	JECdown[i][j]=h_JECdown;
	
	TH1F* h_hfup = (TH1F*)HFupfile->Get("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_HFup");
	HFup[i][j]=h_hfup;
	TH1F* h_hfdown = (TH1F*)HFdownfile->Get("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_HFdown");
	HFdown[i][j]=h_hfdown;

	
	cout << "histos read" << endl;
	
	h_JECup->Add(hist,-1);
	h_JECdown->Add(hist,-1);
	h_hfup->Add(hist,-1);
	h_hfdown->Add(hist,-1);
	TH1F* tmpover=(TH1F*)HFup[i][j]->Clone();
	TH1F* tmplower=(TH1F*)HFup[i][j]->Clone();
	TH1F* tmpJECover=(TH1F*)JECup[i][j]->Clone();
	TH1F* tmpJEClower=(TH1F*)JECup[i][j]->Clone();
	TH1F* tmpHFover=(TH1F*)JECup[i][j]->Clone();
	TH1F* tmpHFlower=(TH1F*)JECup[i][j]->Clone();
	for (int k=1; k<= hist->GetNbinsX();++k){
	  float over_JECup=0;
	  float lower_JECup=0;
	  
	  float over_JECdown=0;
	  float lower_JECdown=0;
	  
	  float over_hfup=0;
	  float lower_hfup=0;
	  
	  float over_hfdown=0;
	  float lower_hfdown=0;
	  if (h_JECup->GetBinContent(k)>0) 	over_JECup=h_JECup->GetBinContent(k); 	  
	  else if (h_JECup->GetBinContent(k)<0)  lower_JECup=h_JECup->GetBinContent(k); 
	  else if (h_JECup->GetBinContent(k)==0) {lower_JECup=0; over_JECup=0;} 
	  
	  if (h_JECdown->GetBinContent(k)>0)	 over_JECdown=h_JECdown->GetBinContent(k); 	  
	  else if (h_JECdown->GetBinContent(k)<0) lower_JECdown=h_JECdown->GetBinContent(k); 
	  else if (h_JECdown->GetBinContent(k)==0)  {lower_JECdown=0; over_JECdown=0;}
	  
	  
	  if (h_hfup->GetBinContent(k)>0)  	over_hfup=h_hfup->GetBinContent(k); 	  
	  else if (h_hfup->GetBinContent(k)<0)   lower_hfup=h_hfup->GetBinContent(k); 
	  else if (h_hfup->GetBinContent(k)==0) {lower_hfup=0;over_hfup=0;} 
	  
	  if (h_hfdown->GetBinContent(k)>0)  	over_hfdown=h_hfdown->GetBinContent(k); 	  
	  else if (h_hfdown->GetBinContent(k)<0) lower_hfdown=h_hfdown->GetBinContent(k);
	  else if (h_hfdown->GetBinContent(k)==0)  {lower_hfdown=0;over_hfdown=0;}
	  
	  float over_JEC=over_JECup+over_JECdown;
	  float lower_JEC=lower_JECup+lower_JECdown;
	  float over_hf=over_hfup+over_hfdown;
	  float lower_hf=lower_hfup+lower_hfdown;
	  float over=pow(over_hf,2)+pow(over_JEC,2);
	  float lower=pow(lower_hf,2)+pow(lower_JEC,2);
	  
	  tmpover->SetBinContent(k,sqrt(over));
	  tmplower->SetBinContent(k,sqrt(lower));
	  tmpJECover->SetBinContent(k,over_JEC);
	  tmpJEClower->SetBinContent(k,lower_JEC);
	  tmpHFover->SetBinContent(k,over_hf);
	  tmpHFlower->SetBinContent(k,lower_hf);
	}
	tmpover->Add(hist);
	tmplower->Add(hist,-1);
	tmplower->Scale(-1);
	
	tmpJECover->Add(hist);
	tmpJEClower->Add(hist,1);
//	tmpJEClower->Scale(-1);
	
	tmpHFover->Add(hist);
	tmpHFlower->Add(hist,1);
 //	tmpHFlower->Scale(-1);
	
	uncover[i][j]=tmpover;
	unclower[i][j]=tmplower;
	uncover[i][j]->SetLineColor(kViolet);
	unclower[i][j]->SetLineColor(kViolet);

	JECover[i][j]=tmpJECover;
	JEClower[i][j]=tmpJEClower;
	JECover[i][j]->SetLineColor(kViolet);
	JEClower[i][j]->SetLineColor(kViolet);
	
	HFover[i][j]=tmpHFover;
	HFlower[i][j]=tmpHFlower;
	HFover[i][j]->SetLineColor(kCyan);
	HFlower[i][j]->SetLineColor(kCyan);
      }
    }
    
  cout << "all histos rdy"<< endl;
  TFile* outfile=new TFile("RESULT.root","RECREATE"); 
  TCanvas* c=new TCanvas();
  TCanvas* c2=new TCanvas();
  TCanvas* c3=new TCanvas();
  TCanvas* c4=new TCanvas();
  TCanvas* c5=new TCanvas();
  TLine* line=new TLine(-0.02,1,1,1);
  line->SetLineColor(kBlack);
  TLegend* leg=new TLegend(0.75,0.4,0.9,0.8);
      leg->SetFillStyle(0);
      leg->SetBorderSize(0);
  
   for (int i=1; i<n_ptbins;++i){
      if (i==0) pt_counter="0";
      else if (i==1) pt_counter="1";
      else if (i==2) pt_counter="2";
      else if (i==3) pt_counter="3";
      else if (i==4) pt_counter="4";
      else if (i==5) pt_counter="5";
      else if (i==6) pt_counter="6";
      else if (i==7) pt_counter="7";
      else if (i==8) pt_counter="8";
      else if (i==9) pt_counter="9";
      for ( int j=1; j<n_etabins;++j){   
	if (j==0) eta_counter="0";
	else if (j==1) eta_counter="1";
	else if (j==2) eta_counter="2";   
	else if (j==3) eta_counter="3"; 
      c->cd(); 
      TLegend* leg=new TLegend(0.1,0.6,0.48,0.9);
      leg->SetFillStyle(0);
      leg->SetBorderSize(0);  
      leg->SetTextSize(0.05),
      
      nominal[i][j]->SetMarkerStyle(5);
      nominal[i][j]->SetMarkerSize(0.7);
      nominal[i][j]->SetTitle("");
      nominal[i][j]->GetXaxis()->SetTitle("CSV");
      nominal[i][j]->GetXaxis()->SetTitleSize(0.05);
      nominal[i][j]->GetXaxis()->SetTitleOffset(0.8);
      nominal[i][j]->GetYaxis()->SetTitle("SF");
      nominal[i][j]->GetYaxis()->SetTitleSize(0.08);
      nominal[i][j]->GetYaxis()->SetTitleOffset(0.45);
      nominal[i][j]->Draw("");   
      nominal[i][j]->SetLineColor(kRed);
      nominal[i][j]->SetMaximum(2);
      nominal[i][j]->SetMinimum(0);
      nominal[i][j]->SetLineWidth(3);
      
      staterror[i][j]->Draw("same e3");
      staterror[i][j]->SetLineColor(kGreen);
      staterror[i][j]->SetFillColorAlpha(kGreen,0.35);
      
      nominaldots[i][j]->Draw("sameeo");
      uncover[i][j]->Draw("same");
      unclower[i][j]->Draw("same");      
      
      line->Draw("same");
      leg->AddEntry(nominal[i][j],"nominal LFSF","L");
      leg->AddEntry(uncover[i][j],"combined systematic uncertainty","L");
      leg->AddEntry(staterror[i][j],"statistical uncertainty","L");
      leg->Draw("same");
      c->SaveAs("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_final.png"); 
      c->Write();
      leg->Delete();
      
      //plot only JEC 
      c2->cd();
      TLegend* leg2=new TLegend(0.1,0.7,0.48,0.9);
      leg2->SetFillStyle(0);
      leg2->SetBorderSize(0);  
      nominal[i][j]->Draw("");
      nominaldots[i][j]->Draw("sameeo");
 
      JECover[i][j]->Draw("same");
      JEClower[i][j]->Draw("same");    
      
      line->Draw("same");
      leg2->AddEntry(nominal[i][j],"nominal LFSF");
      leg2->AddEntry(JECover[i][j],"JEC uncertainty");
      leg2->Draw("same");
      c2->SaveAs("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_JEConly.png"); 
      c2->Write();
      leg2->Delete();
      
      //plot only HF 
      c3->cd();
      TLegend* leg3=new TLegend(0.1,0.7,0.48,0.9);
      leg3->SetFillStyle(0);
      leg3->SetBorderSize(0);  
      nominal[i][j]->Draw("");
      nominaldots[i][j]->Draw("sameeo");
 
      HFover[i][j]->Draw("same");
      HFlower[i][j]->Draw("same");    
      
      line->Draw("same");
      leg3->AddEntry(nominal[i][j],"nominal LFSF");
      leg3->AddEntry(HFover[i][j],"HF uncertainty");
      leg3->Draw("same");
      c3->SaveAs("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_HFonly.png"); 
      c3->Write();
      leg3->Delete();
      
      //plot both systematics
      c5->cd();
      TLegend* leg5=new TLegend(0.1,0.7,0.48,0.9);
      leg5->SetFillStyle(0);
      leg5->SetBorderSize(0);  
      nominal[i][j]->Draw("");
      nominaldots[i][j]->Draw("sameeo");
 
      HFover[i][j]->Draw("same");
      HFlower[i][j]->Draw("same");
      JECover[i][j]->Draw("same");
      JEClower[i][j]->Draw("same");
      
      line->Draw("same");
      leg5->AddEntry(nominal[i][j],"nominal LFSF");
      leg5->AddEntry(HFover[i][j],"HF uncertainty");
      leg5->AddEntry(JECover[i][j],"JEC uncertainty");
      leg5->Draw("same");
      c5->SaveAs("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_systematicsonly.png"); 
      c5->Write();
      leg5->Delete();
      
      
      //plot only Statistical
      c4->cd();
      TLegend* leg4=new TLegend(0.1,0.7,0.48,0.9);
      leg4->SetFillStyle(0);
      leg4->SetBorderSize(0);    
      nominal[i][j]->Draw("");
      staterror[i][j]->Draw("same e3"); 
      nominaldots[i][j]->Draw("sameeo");      
      line->Draw("same");
      leg4->AddEntry(nominal[i][j],"nominal LFSF");
      leg4->AddEntry(staterror[i][j],"statistical uncertainty");
      leg4->Draw("same");
      c4->SaveAs("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_statonly.png"); 
      c4->Write();
      leg4->Delete();
    }
  }

  outfile->Close();
  
  //compare to official SF
  TFile* officialfile=new TFile("csv_rwt_fit_lf_2015_11_20.root");
  n_ptbins= 4;
  n_etabins=3;
  vector<vector<TH1F*>> official;
  official.resize(n_ptbins, vector<TH1F*>(n_etabins, 0));
  cout << "read official histos" << endl;
  for (int i=0; i<n_ptbins;++i){
      if (i==0) pt_counter="0";
      else if (i==1) pt_counter="1";
      else if (i==2) pt_counter="2";
      else if (i==3) pt_counter="3";
      for ( int j=0; j<n_etabins;++j){   
	if (j==0) eta_counter="0";
	else if (j==1) eta_counter="1";
	else if (j==2) eta_counter="2";   
	TH1F* h = (TH1F*)officialfile->Get("csv_ratio_Pt"+pt_counter+"_Eta"+eta_counter+"_final");
	official[i][j]=h;
	official[i][j]->SetStats(0);
      }
  }
  
  TFile* outfile_comp=new TFile("comparison.root","RECREATE"); 
  TCanvas* c_comp=new TCanvas();
  for (int i=1; i<n_ptbins;++i){
      if (i==0) pt_counter="0";
      else if (i==1) pt_counter="1";
      else if (i==2) pt_counter="2";
      else if (i==3) pt_counter="3";
      for ( int j=1; j<n_etabins;++j){   
	if (j==0) eta_counter="0";
	else if (j==1) eta_counter="1";
	else if (j==2) eta_counter="2";   
      c_comp->cd(); 
      TLegend* leg=new TLegend(0.1,0.6,0.48,0.9);
      leg->SetFillStyle(0);
      leg->SetBorderSize(0);  
      leg->SetTextSize(0.05),
      
      nominal[i][j]->SetMarkerStyle(5);
      nominal[i][j]->SetMarkerSize(0.7);
      nominal[i][j]->SetTitle("");
      nominal[i][j]->GetXaxis()->SetTitle("CSV");
      nominal[i][j]->GetXaxis()->SetTitleSize(0.05);
      nominal[i][j]->GetXaxis()->SetTitleOffset(0.8);
      nominal[i][j]->GetYaxis()->SetTitle("SF");
      nominal[i][j]->GetYaxis()->SetTitleSize(0.08);
      nominal[i][j]->GetYaxis()->SetTitleOffset(0.45);
      nominal[i][j]->Draw("");   
      nominal[i][j]->SetLineColor(kRed);
      nominal[i][j]->SetMaximum(2);
      nominal[i][j]->SetMinimum(0);
      nominal[i][j]->SetLineWidth(3);
      
      staterror[i][j]->Draw("same e3");
      staterror[i][j]->SetLineColor(kGreen);
      staterror[i][j]->SetFillColorAlpha(kGreen,0.35);
      
      nominaldots[i][j]->Draw("sameeo");
      uncover[i][j]->Draw("same");
      unclower[i][j]->Draw("same");  
      
      official[i][j]->Draw("same");
      official[i][j]->SetLineColor(kBlue);
      official[i][j]->SetLineWidth(3);
      
      line->Draw("same");
      leg->AddEntry(official[i][j],"official LFSF","L");
      leg->AddEntry(nominal[i][j],"nominal LFSF","L");
      leg->AddEntry(uncover[i][j],"combined systematic uncertainty","L");
      leg->AddEntry(staterror[i][j],"statistical uncertainty","L");

      leg->Draw("same");
      c_comp->SaveAs("LFSF_pt"+pt_counter+"_eta"+eta_counter+"_comparison.pdf"); 
      c_comp->Write();
      leg->Delete();
      }
  }


  
  

//   outfile->Write();


  outfile_comp->Close();

  
  
		     
}
示例#3
0
文件: Trig_eff_DS.C 项目: XuQiao/HI
void Calc(TString Generatorfile,TString outfile) {

    TFile *fin = TFile::Open(Generatorfile);
    TFile *fout = TFile::Open(outfile,"RECREATE");

    TH1F *hHFEnergy4 = new TH1F("hHFEnergy4","HFEnergy Distribution before Trigger selection",10000,0,100);
    hHFEnergy4->Sumw2();
    TH1F *hHFEnergy4_tr = new TH1F("hHFEnergy4_tr","HFEnergy Distribution after Trigger selection",10000,0,100);
    hHFEnergy4_tr->Sumw2();
    TH1F *hHFEnergy4_DS = new TH1F("hHFEnergy4_DS","HFEnergy Distribution after Doudle Side event selection",10000,0,100);
    hHFEnergy4_DS->Sumw2();
    TH1F *hHFEnergyPlus4 = new TH1F("hHFEnergyPlus4","HFEnergy Distribution before Trigger selection",10000,0,100);
    hHFEnergyPlus4->Sumw2();
    TH1F *hHFEnergyPlus4_tr = new TH1F("hHFEnergyPlus4_tr","HFEnergy Distribution after Trigger selection",10000,0,100);
    hHFEnergyPlus4_tr->Sumw2();
    TH1F *hHFEnergyPlus4_DS = new TH1F("hHFEnergyPlus4_DS","HFEnergy Distribution after Double Side event selection",10000,0,100);
    hHFEnergyPlus4_DS->Sumw2();
    TH1F *hHFEnergyPlus = new TH1F("hHFEnergyPlus","HFEnergy Distribution before Trigger selection",10000,0,100);
    hHFEnergyPlus->Sumw2();
    TH1F *hHFEnergyPlus_tr = new TH1F("hHFEnergyPlus_tr","HFEnergy Distribution after Trigger selection",10000,0,100);
    hHFEnergyPlus_tr->Sumw2();
    TH1F *hHFEnergyPlus_DS = new TH1F("hHFEnergyPlus_DS","HFEnergy Distribution after Double Side event selection",10000,0,100);
    hHFEnergyPlus_DS->Sumw2();

    TTree *tree;
    fin->cd();
    tree=(TTree*)hiEvtAnalyzer->Get("HiTree");
    tree->AddFriend("skimTree=skimanalysis/HltTree");
    tree->AddFriend("hltTree=hltanalysis/HltTree");
    tree->AddFriend("genpartTree=genparticles/hi");

    const int Maxmult=10000;
    Float_t hiHF, vz, hiHFplus,eta[Maxmult];
    Float_t hiHFminusEta4, hiHFplusEta4;
    Long_t Ev,Nevent, Nevent_counter, Nleft;
    Int_t n, HLT_PAZeroBiasPixel_SingleTrack_v1, pprimaryvertexFilter, pVertexFilterCutGplus, pPAcollisionEventSelectionPA, pHBHENoiseFilter,phfPosFilter1, phfNegFilter1,pBeamScrapingFilter;
    Int_t Nskim=0;
    double weight;
    int mult, nDS=0, nPlus35, nMinus35;
    int sta[Maxmult];
    Nevent_counter=0;
    Nleft=0;
    Nevent=tree->GetEntries();

    tree->SetBranchAddress("hiHF",&hiHF);//HF energy
    tree->SetBranchAddress("hiHFplus",&hiHFplus);//HF energy positive
    tree->SetBranchAddress("hiHFplusEta4",&hiHFplusEta4);//HF energy positive 4 to 5
    tree->SetBranchAddress("hiHFminusEta4",&hiHFminusEta4);//HF energy negative -5 to -4
    tree->SetBranchAddress("vz",&vz);
    tree->SetBranchAddress("HLT_PAZeroBiasPixel_SingleTrack_v1",&HLT_PAZeroBiasPixel_SingleTrack_v1);
    tree->SetBranchAddress("pprimaryvertexFilter",&pprimaryvertexFilter);
    tree->SetBranchAddress("pVertexFilterCutGplus",&pVertexFilterCutGplus);
//tree->SetBranchAddress("pHBHENoiseFilter",&pHBHENoiseFilter);
    tree->SetBranchAddress("pPAcollisionEventSelectionPA",&pPAcollisionEventSelectionPA);
    tree->SetBranchAddress("phfPosFilter1",&phfPosFilter1);
    tree->SetBranchAddress("phfNegFilter1",&phfNegFilter1);
    tree->SetBranchAddress("pBeamScrapingFilter",&pBeamScrapingFilter);
    tree->SetBranchAddress("eta",&eta);
    tree->SetBranchAddress("sta",&sta);
    tree->SetBranchAddress("mult",&mult);

    TF1 * fVz = new TF1("fVx","[0]+[1]*x+[2]*TMath::Power(x,2)+[3]*TMath::Power(x,3)+[4]*TMath::Power(x,4)", -15., 15.);
    fVz->SetParameters(1.60182e+00,1.08425e-03,-1.29156e-02,-7.24899e-06,2.80750e-05);

    for(Ev=0; Ev<Nevent; Ev++) {

        tree->GetEntry(Ev);
        weight=1.;
//weight*=fVz->Eval(vz);
        if(Ev%5000==0)
            cout<<"Have run "<<Ev<<" Events"<<endl;
//cout<<"weight="<<weight<<endl;

        hHFEnergy4->Fill(hiHFplusEta4+hiHFminusEta4,weight);
        hHFEnergyPlus4->Fill(hiHFplusEta4,weight);
        hHFEnergyPlus->Fill(hiHFplus,weight);
        Nevent_counter++;

        nPlus35=0;
        nMinus35=0;
        for(int j=0; j<mult; j++) {
            if(eta[j]>3&&eta[j]<5&&sta[j]==1) nPlus35++;
            if(eta[j]>-5&&eta[j]<-3&&sta[j]==1) nMinus35++;
        }
        if(nPlus35>=1 && nMinus35>=1 && TMath::Abs(vz)<15) {
            hHFEnergy4_DS->Fill(hiHFplusEta4+hiHFminusEta4,weight);
            hHFEnergyPlus4_DS->Fill(hiHFplusEta4,weight);
            hHFEnergyPlus_DS->Fill(hiHFplus,weight);
            nDS++;
        }
        if(!(HLT_PAZeroBiasPixel_SingleTrack_v1 && pVertexFilterCutGplus && pPAcollisionEventSelectionPA && pprimaryvertexFilter && TMath::Abs(vz)<15))
//if(!(HLT_PAZeroBiasPixel_SingleTrack_v1 && pVertexFilterCutGplus && pBeamScrapingFilter && phfPosFilter1 && phfNegFilter1 && pprimaryvertexFilter && TMath::Abs(vz)<15))
        {
            Nskim++;
            continue;
        }

        hHFEnergy4_tr->Fill(hiHFplusEta4+hiHFminusEta4,weight);
        hHFEnergyPlus4_tr->Fill(hiHFplusEta4,weight);
        hHFEnergyPlus_tr->Fill(hiHFplus,weight);
        Nleft++;
    }
    cout<<Nevent_counter<<endl;
    cout<<nDS<<endl;
    cout<<Nleft<<endl;
    fout->cd();
    hHFEnergy4->Write();
    hHFEnergy4_tr->Write();
    hHFEnergy4_DS->Write();

    hHFEnergyPlus4->Write();
    hHFEnergyPlus4_tr->Write();
    hHFEnergyPlus4_DS->Write();

    hHFEnergyPlus->Write();
    hHFEnergyPlus_tr->Write();
    hHFEnergyPlus_DS->Write();

    fin->Close();
    fout->Close();

    gROOT->Reset();

}
示例#4
0
void bananaDeltaCut(char* filename)
{
    TFile *f = new TFile(filename);

    TTree *t1 = (TTree*)f->Get("ntp1");

    // Declare the variables we will need.
    int nB;
    // Note that these are arrays, because you may
    // have multiple B-candidates.
    float BpostFitMes[100];
    float BpostFitDeltaE[100];
    int Bd1Idx[100], Bd2Idx[100];
    int Bd1Lund[100], Bd2Lund[100];
    float DeltappMass[100];
    float percentDiff;
    float bestVal = 999.0;
    int bestEntry = 0;

    int signalpeak = 0;
    int signaltail = 0;

    // Initialize the addresses (?)
    t1->SetBranchAddress("nB",&nB);
    // Because these are arrays, we don't need the ampersand
    // for the second argument.
    t1->SetBranchAddress("BpostFitMes",BpostFitMes);
    t1->SetBranchAddress("BpostFitDeltaE",BpostFitDeltaE);
    t1->SetBranchAddress("Bd1Idx",Bd1Idx);
    t1->SetBranchAddress("Bd2Idx",Bd2Idx);
    t1->SetBranchAddress("Bd1Lund",Bd1Lund);
    t1->SetBranchAddress("Bd2Lund",Bd2Lund);
    t1->SetBranchAddress("DeltappMass",DeltappMass);

    // Create some empty histograms
    //    TH1F *hnB          = new TH1F("hnB","The number of B candidates",10,0,10);
    TH1F *DelMCutbestCandMass = new TH1F("DelMCutbestCandMass","m_{ES}",40,5.2,5.3);
    TH1F *DelMCutbestCandDelE = new TH1F("DelMCutbestCandDelE","#Delta E",40,-0.1,0.1);
    TH2F *DelMCutmESvsDelE    = new TH2F("DelMCutmESvsDelE","m_{ES} vs. #Delta E",40,5.2,5.3,40,-0.1,0.1);

    TH1F *DelMCutmassDeltapp  = new TH1F("DelMCutmassDeltapp","#Delta++ mass",40,1.0,1.7);

    // Name the images
    

    // Get the number of entries in this file.
    Int_t nentries = (Int_t)t1->GetEntries();

    // Loop over the entries
    for (Int_t i=0;i<nentries;i++) {

      t1->GetEntry(i);

      if (nB == 1) {
	if ( DeltappMass[Bd2Idx[0]] > 1.4 ) {
	  DelMCutbestCandMass->Fill(BpostFitMes[0]);
	  DelMCutbestCandDelE->Fill(BpostFitDeltaE[0]);
	  DelMCutmESvsDelE->Fill(BpostFitMes[0],BpostFitDeltaE[0]);
	  
	  DelMCutmassDeltapp->Fill(DeltappMass[Bd2Idx[0]]);	  

	if (BpostFitMes[0] < (5.279 + 0.008) && BpostFitMes[0] > (5.279-0.008)) signalpeak++;
	if (BpostFitMes[0] < (5.279 - 0.008) || BpostFitMes[0] > (5.279+0.008)) signaltail++;

	}
      }
      else {
	for (Int_t j=0;j<nB;j++) {
	  percentDiff = fabs(BpostFitMes[j]-5.279);
	  if (percentDiff < bestVal) {
	    bestVal = percentDiff;
	    bestEntry = j;
	  }
	}
	if ( DeltappMass[Bd2Idx[bestEntry]] > 1.4 ) {
	  DelMCutbestCandMass->Fill(BpostFitMes[bestEntry]);
	  DelMCutbestCandDelE->Fill(BpostFitDeltaE[bestEntry]);
	  DelMCutmESvsDelE->Fill(BpostFitMes[bestEntry],BpostFitDeltaE[bestEntry]);
	  
	  DelMCutmassDeltapp->Fill(DeltappMass[Bd2Idx[bestEntry]]);

	if (BpostFitMes[bestEntry] < (5.279 + 0.008) && BpostFitMes[bestEntry] > (5.279-0.008)) signalpeak++;
	if (BpostFitMes[bestEntry] < (5.279 - 0.008) || BpostFitMes[bestEntry] > (5.279+0.008)) signaltail++;

	}
      }
    }

    DelMCutbestCandMass->Draw();
    // c1->SaveAs("DelMCutbestCandMassMulticand.png");
    // c1->Clear();
    
    // DelMCutbestCandDelE->Draw();
    // c1->SaveAs("DelMCutbestCandDelEMulticand.png");
    // c1->Clear();

    // DelMCutmESvsDelE->Draw();
    // c1->SaveAs("DelMCutmESvsDelEMulticand2.png");
    // c1->Clear();

    // DelMCutmassDeltapp->Draw();
    // c1->SaveAs("DelMCutmassDeltapp2.png");
    // c1->Clear();

    cout << "The number of candidates in the peak was " << signalpeak << endl;
    cout << "The number of candidates in the tail was " << signaltail << endl;

}
void v_beam_asymmetry(){

	TString Q2 = "1.0";

	int HeRunNumberL = 1686;
	int endHeRunNumberL = 1958;
	int HeRunNumberR = 20596;
	int endHeRunNumberR = 20789;
// NOTE: There is a problem with the charge scalar in runs 20812-20879. When this is fixed,
// uncomment the line below. Until then, we stop at run 20789.
//	int endHeRunNumberR = 20879;
	
	double bins = 50;
	double xmin = 0.6;
	double xmax = 1.6;

	// Defines Right Arm Cuts
	TCut cutR = "";
	TCut kinematicsR = "PriKineR.Q2<10 && GoodElectron==1 && PriKineR.nu<10";
	TCut eventtypeR = "(D.evtypebits&2)==2";
	TCut goldR = "ExTgtCor_R.dp>-0.04 && ExTgtCor_R.dp<0.053";
	TCut targetR = "ReactPt_R.z>-0.17 && ReactPt_R.z<0.175";
	TCut thetaphiR = "abs(ExTgtCor_R.ph)<0.03 && abs(ExTgtCor_R.th)<0.06";

	TCut cutsR = cutR && kinematicsR && eventtypeR && goldR && targetR && thetaphiR;

	// Defines Left Arm Cuts
	TCut cutL = "";
	TCut kinematicsL = "PriKineL.Q2<10 && GoodElectron==1 && PriKineL.nu<10";
//	TCut eventtypeL = "(D.evtypebits&2)==2";
	TCut eventtypeL = "";
	TCut goldL = "ExTgtCor_L.dp>-0.04 && ExTgtCor_L.dp<0.053";
	TCut targetL = "ReactPt_L.z>-0.17 && ReactPt_L.z<0.175";
	TCut thetaphiL = "abs(ExTgtCor_L.ph)<0.03 && abs(ExTgtCor_L.th)<0.06";

	TCut cutsL = cutL && kinematicsL && eventtypeL && goldL && targetL && thetaphiL;


	TChain* chainHeR = new TChain("T");
	TChain* chainHeL = new TChain("T");

	TString filenameHeR;
	TString filenameHeL;

// ******************* The section below adds files to the Right arm chain from the RHRS ********************
	for (int thisHeRunNumberR=HeRunNumberR; thisHeRunNumberR<(endHeRunNumberR+1); thisHeRunNumberR++)
	{
		// Skipping Vertical Carbon & Deuterium Runs
		if(thisHeRunNumberR==20591){thisHeRunNumberR=20596;}
		if(thisHeRunNumberR==20731){thisHeRunNumberR=20738;}
		if(thisHeRunNumberR==20732){thisHeRunNumberR=20738;}
		if(thisHeRunNumberR==20733){thisHeRunNumberR=20738;}
		if(thisHeRunNumberR==20734){thisHeRunNumberR=20738;}
		if(thisHeRunNumberR==20736){thisHeRunNumberR=20738;}
		if(thisHeRunNumberR==20737){thisHeRunNumberR=20738;}
		if(thisHeRunNumberR==20762){thisHeRunNumberR=20789;}
		if(thisHeRunNumberR==20763){thisHeRunNumberR=20789;}
		if(thisHeRunNumberR==20764){thisHeRunNumberR=20789;}
		if(thisHeRunNumberR==20791){thisHeRunNumberR=20814;}
		if(thisHeRunNumberR==20792){thisHeRunNumberR=20814;}

		// Skipping Longitudinal Carbon Runs
		if(thisHeRunNumberR==22380){thisHeRunNumberR=22393;}
		if(thisHeRunNumberR==22389){thisHeRunNumberR=22393;}
		if(thisHeRunNumberR==22425){thisHeRunNumberR=22436;}
		if(thisHeRunNumberR==22426){thisHeRunNumberR=22436;}

		// Skipping Transverse Carbon Runs
		if(thisHeRunNumberR==22461){thisHeRunNumberR=22465;}

		// Adds runs to the chain
		for (int t=0; t<1000; t++)
		{
			filenameHeR = "/home/ellie/physics/e05-102/terabyte/ROOTfiles/e05102_R_";
			filenameHeR += thisHeRunNumberR;
			if (t != 0)
			{
				filenameHeR += "_";
				filenameHeR += t;
			}
			filenameHeR += ".root";
			ifstream ifileHeR(filenameHeR);
			if (ifileHeR)
			{
				cout << "Adding file to chainHeR: " << filenameHeR << endl;
				chainHeR->Add(filenameHeR);
			}
			else
			{
				cout << "File " << filenameHeR << " does not exist. Ending here." << endl;
				t=999999999;
			}
		}
//		 Use the line below only for debugging purposes. It will only add the first file.
//		 thisHeRunNumberR=999999;
	}
// ***********************************************************************************************************

// ************************** The section below adds files to the Left arm chain from the LHRS ***************
	for (int thisHeRunNumberL=HeRunNumberL; thisHeRunNumberL<(endHeRunNumberL+1); thisHeRunNumberL++)
	{
		// Skipping Vertical Carbon and Deuterium Runs
		if(thisHeRunNumberL==1699){thisHeRunNumberL=1705;}
		if(thisHeRunNumberL==1825){thisHeRunNumberL=1832;}
		if(thisHeRunNumberL==1826){thisHeRunNumberL=1832;}
		if(thisHeRunNumberL==1827){thisHeRunNumberL=1832;}
		if(thisHeRunNumberL==1828){thisHeRunNumberL=1832;}
		if(thisHeRunNumberL==1830){thisHeRunNumberL=1832;}
		if(thisHeRunNumberL==1831){thisHeRunNumberL=1832;}
		if(thisHeRunNumberL==1884){thisHeRunNumberL=1905;}
		if(thisHeRunNumberL==1885){thisHeRunNumberL=1905;}

		// Skipping Longitudinal Carbon Runs
		if(thisHeRunNumberL==22380){thisHeRunNumberL=22393;}
		if(thisHeRunNumberL==22389){thisHeRunNumberL=22393;}
		if(thisHeRunNumberL==22425){thisHeRunNumberL=22436;}
		if(thisHeRunNumberL==22426){thisHeRunNumberL=22436;}

		// Skipping Transverse Carbon Runs
		if(thisHeRunNumberL==22461){thisHeRunNumberL=22465;}

		// Adds runs to the chain
		for (int t=0; t<1000; t++)
		{
			filenameHeL = "/home/ellie/physics/e05-102/terabyte/ROOTfiles/e05102_L_";
			filenameHeL += thisHeRunNumberL;
			if (t != 0)
			{
				filenameHeL += "_";
				filenameHeL += t;
			}
			filenameHeL += ".root";
			ifstream ifileHeL(filenameHeL);
			if (ifileHeL)
			{
				cout << "Adding file to chainHeL: " << filenameHeL << endl;
				chainHeL->Add(filenameHeL);
			}
			else
			{
				cout << "File " << filenameHeL << " does not exist. Ending here." << endl;
				t=999999999;
			}
		}
//		 Use the line below only for debugging purposes. It will only add the first file.
//		 thisHeRunNumberL=999999;
	}
// ****************************************************************************************************************




	gStyle->SetPalette(1);
	
	// Defines Canvas
	TCanvas *c1 = new TCanvas("c1","Asymmetry",1360,810); //x,y
	pad1  =  new  TPad("pad1","pad1",0.0000,0.6666,0.2500,1.0000,0,0,0);
	pad2  =  new  TPad("pad2","pad2",0.2500,0.6666,0.5000,1.0000,0,0,0);
	pad3  =  new  TPad("pad3","pad3",0.5000,0.6666,0.7500,1.0000,0,0,0);
	pad4  =  new  TPad("pad4","pad4",0.7500,0.6666,1.0000,1.0000,0,0,0);
	pad5  =  new  TPad("pad5","pad5",0.0000,0.3333,0.2000,0.6666,0,0,0);
	pad6  =  new  TPad("pad6","pad6",0.2000,0.3333,0.4000,0.6666,0,0,0);
	pad7  =  new  TPad("pad7","pad7",0.4000,0.3333,0.6000,0.6666,0,0,0);
	pad8  =  new  TPad("pad8","pad8",0.6000,0.3333,0.8000,0.6666,0,0,0);
	pad9  =  new  TPad("pad9","pad9",0.8000,0.3333,1.0000,0.6666,0,0,0);
	pad10 = new TPad("pad10","pad10",0.0000,0.0000,0.5000,0.3333,0,0,0);
	pad11 = new TPad("pad11","pad11",0.5000,0.0000,1.0000,0.3333,0,0,0);
	pad1->Draw();pad2->Draw();pad3->Draw();pad4->Draw();pad5->Draw();pad6->Draw();pad7->Draw();pad8->Draw();pad9->Draw();pad10->Draw();pad11->Draw();



	// Everything below here makes graphs for each section of the canvas

	pad1->cd();
	TString titledp = "dp Cut";
	cout << "Drawing " << titledp << "..." << endl;
	TH1F *HedpNoCut = new TH1F("HedpNoCut",titledp,400,-0.08,0.08);
	TH1F *HedpCut = new TH1F("HedpCut",titledp,400,-0.08,0.08);
	chainHeR->Draw("ExTgtCor_R.dp>>HedpNoCutR(400,-0.08,0.08)", "", "");
	chainHeR->Draw("ExTgtCor_R.dp>>HedpCutR(400,-0.08,0.08)", goldR, "");
	chainHeL->Draw("ExTgtCor_L.dp>>HedpNoCutL(400,-0.08,0.08)", "", "");
	chainHeL->Draw("ExTgtCor_L.dp>>HedpCutL(400,-0.08,0.08)", goldL, "");
	HedpNoCut->Add(HedpNoCutR,HedpNoCutL);
	HedpNoCut->SetTitle(titledp);
	HedpNoCut->Draw();
	HedpCut->Add(HedpCutR,HedpCutL);
	HedpCut->SetLineColor(kBlack);
	HedpCut->SetFillColor(kViolet);
	HedpCut->Draw("same");

	pad2->cd();
	cout << "Drawing Target Cut..." << endl;
	TString titleTarget = "Target Cut";
	TH1F *HeReactZNoCut = new TH1F("HeReactZNoCut",titleTarget,400,-0.3,0.3);
	TH1F *HeReactZCut = new TH1F("HeReactZCut",titleTarget,400,-0.3,0.3);
	chainHeR->Draw("ReactPt_R.z>>HeReactZNoCutR(400,-0.3,0.3)", "", "");
	chainHeR->Draw("ReactPt_R.z>>HeReactZCutR(400,-0.3,0.3)", targetR, "");
	chainHeL->Draw("ReactPt_L.z>>HeReactZNoCutL(400,-0.3,0.3)", "", "");
	chainHeL->Draw("ReactPt_L.z>>HeReactZCutL(400,-0.3,0.3)", targetL, "");
	HeReactZNoCut->Add(HeReactZNoCutR,HeReactZNoCutL);
	HeReactZNoCut->SetTitle(titleTarget);
	HeReactZNoCut->Draw();
	HeReactZCut->Add(HeReactZCutR,HeReactZCutL);
	HeReactZCut->SetLineColor(kBlack);
	HeReactZCut->SetFillColor(kViolet);
	HeReactZCut->Draw("same");

	pad3->cd();
	cout << "Drawing Theta and Phi..." << endl;
	TString titleThetaPhiNoCut = "Theta and Phi, No Cut";
	TH2F *HeThetaPhiNoCut = new TH2F("HeThetaPhiNoCut",titleThetaPhiNoCut,100,-0.05,0.05,100,-0.1,0.1);
	chainHeR->Draw("ExTgtCor_R.th:ExTgtCor_R.ph>>HeThetaPhiNoCutR(100,-0.05,0.05,100,-0.1,0.1)", targetR, "");
	chainHeL->Draw("ExTgtCor_L.th:ExTgtCor_L.ph>>HeThetaPhiNoCutL(100,-0.05,0.05,100,-0.1,0.1)", targetL, "");
	HeThetaPhiNoCut->Add(HeThetaPhiNoCutR,HeThetaPhiNoCutL);
	HeThetaPhiNoCut->SetTitle(titleThetaPhiNoCut);
	HeThetaPhiNoCut->SetStats(kFALSE);
	HeThetaPhiNoCut->Draw("COLZ");

	pad4->cd();
	cout << "Drawing Theta and Phi Cut..." << endl;
	TString titleThetaPhi = "Theta and Phi Cut";
	TH2F *HeThetaPhiCut = new TH2F("HeThetaPhiCut",titleThetaPhi,100,-0.05,0.05,100,-0.1,0.1);
	chainHeR->Draw("ExTgtCor_R.th:ExTgtCor_R.ph>>HeThetaPhiCutR(100,-0.05,0.05,100,-0.1,0.1)", targetR && thetaphiR, "");
	chainHeL->Draw("ExTgtCor_L.th:ExTgtCor_L.ph>>HeThetaPhiCutL(100,-0.05,0.05,100,-0.1,0.1)", targetL && thetaphiL, "");
	HeThetaPhiCut->Add(HeThetaPhiCutR,HeThetaPhiCutL);
	HeThetaPhiCut->SetTitle(titleThetaPhi);
	HeThetaPhiCut->SetStats(kFALSE);
	HeThetaPhiCut->Draw("COLZ");

	pad5->cd();
	TString titleQ2 = "Q2";
	TH1F *histQ2 = new TH1F("histQ2",titleQ2,400,0,1.6);
	cout << "Drawing " << titleQ2 << "..." << endl;
	chainHeR->Draw("PriKineR.Q2>>histQ2R(400,0,1.6)", cutsR, "");	
	chainHeL->Draw("PriKineL.Q2>>histQ2L(400,0,1.6)", cutsL, "");
	histQ2->Add(histQ2R,histQ2L);
	histQ2->SetTitle(titleQ2);
	histQ2->SetStats(kFALSE);
	histQ2->Draw();

	pad6->cd();
	TString titleNu = "Nu";
	cout << "Drawing " << titleNu << "..." << endl;
	TH1F *histNu = new TH1F("histNu",titleNu,100,0.3,0.8);
	chainHeR->Draw("PriKineR.nu>>histNuR(100,0.3,0.8)", cutsR, "");
	chainHeL->Draw("PriKineL.nu>>histNuL(100,0.3,0.8)", cutsL, "");
	histNu->Add(histNuR,histNuL);
	histNu->SetTitle(titleNu);
	histNu->SetStats(kFALSE);
	histNu->Draw();

	pad7->cd();
	TString titleHel = "Helicity vs. Bjorken x";
	cout << "Drawing " << titleHel << "..." << endl;
	TH2F *histHelR = new TH2F("histHelR",titleHel,bins,xmin,xmax,7,-2,2);
	TH2F *histHelL = new TH2F("histHelL",titleHel,bins,xmin,xmax,7,-2,2);
	TH2F *histHel = new TH2F("histHel",titleHel,bins,xmin,xmax,7,-2,2);
	chainHeR->Draw("g0hel.R.helicity:(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histHelR", cutsR, "");
	chainHeL->Draw("g0hel.L.helicity:(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histHelL", cutsL, "");
	histHel->Add(histHelR,histHelL);
	histHel->Draw("COLZ");


	// Note: For all plots below, Positive Helicity is defined as g0hel.R.helicity==1 when the BHWP is In
	// and g0hel.R.helicity==-1 when the BHWP is Out
	pad8->cd();
	TString titlePosHelx = "# of Positive Helicity Events vs. Bjorken x";
	cout << "Drawing " << titlePosHelx << "..." << endl;
	TH1F *histPosHelxIn1R = new TH1F("histPosHelxIn1R",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxIn2R = new TH1F("histPosHelxIn2R",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxInR = new TH1F("histPosHelxInR",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxOut1R = new TH1F("histPosHelxOut1R",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxOut2R = new TH1F("histPosHelxOut2R",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxOutR = new TH1F("histPosHelxOutR",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxIn1L = new TH1F("histPosHelxIn1L",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxIn2L = new TH1F("histPosHelxIn2L",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxInL = new TH1F("histPosHelxInL",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxOut1L = new TH1F("histPosHelxOut1L",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxOut2L = new TH1F("histPosHelxOut2L",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxOutL = new TH1F("histPosHelxOutL",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxR = new TH1F("histPosHelxL",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelxL = new TH1F("histPosHelxR",titlePosHelx,bins,xmin,xmax);
	TH1F *histPosHelx = new TH1F("histPosHelx",titlePosHelx,bins,xmin,xmax);
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histPosHelxIn1R", cutsR && "g0hel.R.helicity==1" && "fEvtHdr.fRun>20576" && "fEvtHdr.fRun<20684", "");
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histPosHelxIn2R", cutsR && "g0hel.R.helicity==1" && "fEvtHdr.fRun>20728" && "fEvtHdr.fRun<20813", "");
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histPosHelxOut1R", cutsR && "g0hel.R.helicity==-1" && "fEvtHdr.fRun>20683" && "fEvtHdr.fRun<20728", "");
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histPosHelxOut2R", cutsR && "g0hel.R.helicity==-1" && "fEvtHdr.fRun>20813" && "fEvtHdr.fRun<20879", "");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histPosHelxIn1L", cutsL && "g0hel.L.helicity==1" && "fEvtHdr.fRun>1685" && "fEvtHdr.fRun<1778", "");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histPosHelxIn2L", cutsL && "g0hel.L.helicity==1" && "fEvtHdr.fRun>1822" && "fEvtHdr.fRun<1905", "");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histPosHelxOut1L", cutsL && "g0hel.L.helicity==-1" && "fEvtHdr.fRun>1777" && "fEvtHdr.fRun<1823", "");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histPosHelxOut2L", cutsL && "g0hel.L.helicity==-1" && "fEvtHdr.fRun>1905" && "fEvtHdr.fRun<1960", "");
	histPosHelxInR->Add(histPosHelxIn1R,histPosHelxIn2R);
	histPosHelxOutR->Add(histPosHelxOut1R,histPosHelxOut2R);
	histPosHelxR->Add(histPosHelxInR,histPosHelxOutR);
	histPosHelxInL->Add(histPosHelxIn1L,histPosHelxIn2L);
	histPosHelxOutL->Add(histPosHelxOut1L,histPosHelxOut2L);
	histPosHelxL->Add(histPosHelxInL,histPosHelxOutL);
	histPosHelx->Add(histPosHelxR,histPosHelxL);
	histPosHelx->Draw();

	pad9->cd();
	TString titleNegHelx = "# of Negative Helicity Events vs. Bjorken x";
	cout << "Drawing " << titleNegHelx << "..." << endl;
	TH1F *histNegHelxIn1R = new TH1F("histNegHelxIn1R",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxIn2R = new TH1F("histNegHelxIn2R",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxInR = new TH1F("histNegHelxInR",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxOut1R = new TH1F("histNegHelxOut1R",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxOut2R = new TH1F("histNegHelxOut2R",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxOutR = new TH1F("histNegHelxOutR",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxR = new TH1F("histNegHelxR",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxIn1L = new TH1F("histNegHelxIn1L",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxIn2L = new TH1F("histNegHelxIn2L",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxInL = new TH1F("histNegHelxInL",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxOut1L = new TH1F("histNegHelxOut1L",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxOut2L = new TH1F("histNegHelxOut2L",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxOutL = new TH1F("histNegHelxOutL",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelxL = new TH1F("histNegHelxL",titleNegHelx,bins,xmin,xmax);
	TH1F *histNegHelx = new TH1F("histNegHelx",titleNegHelx,bins,xmin,xmax);
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histNegHelxIn1R", cutsR && "g0hel.R.helicity==-1" && "fEvtHdr.fRun>20576" && "fEvtHdr.fRun<20684", "");
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histNegHelxIn2R", cutsR && "g0hel.R.helicity==-1" && "fEvtHdr.fRun>20728" && "fEvtHdr.fRun<20813", "");
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histNegHelxOut1R", cutsR && "g0hel.R.helicity==1" && "fEvtHdr.fRun>20683" && "fEvtHdr.fRun<20728", "");
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histNegHelxOut2R", cutsR && "g0hel.R.helicity==1" && "fEvtHdr.fRun>20813" && "fEvtHdr.fRun<20879", "");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histNegHelxIn1L", cutsL && "g0hel.L.helicity==-1" && "fEvtHdr.fRun>1685" && "fEvtHdr.fRun<1778", "");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histNegHelxIn2L", cutsL && "g0hel.L.helicity==-1" && "fEvtHdr.fRun>1822" && "fEvtHdr.fRun<1905", "");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histNegHelxOut1L", cutsL && "g0hel.L.helicity==1" && "fEvtHdr.fRun>1777" && "fEvtHdr.fRun<1823", "");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histNegHelxOut2L", cutsL && "g0hel.L.helicity==1" && "fEvtHdr.fRun>1905" && "fEvtHdr.fRun<1960", "");
	histNegHelxInR->Add(histNegHelxIn1R,histNegHelxIn2R);
	histNegHelxInL->Add(histNegHelxIn1L,histNegHelxIn2L);
	histNegHelxOutR->Add(histNegHelxOut1R,histNegHelxOut2R);
	histNegHelxOutL->Add(histNegHelxOut1L,histNegHelxOut2L);
	histNegHelxR->Add(histNegHelxInR,histNegHelxOutR);
	histNegHelxL->Add(histNegHelxInL,histNegHelxOutL);
	histNegHelx->Add(histNegHelxR,histNegHelxL);
	histNegHelx->Draw();

	pad10->cd();
	TString titlex = "Bjorken x ";
	titlex += " (x=Q^2/[2m*nu])";
	cout << "Drawing " << titlex << "..." << endl;
	TH1F *histxR = new TH1F("histxR",titlex,bins,xmin,xmax);
	TH1F *histxL = new TH1F("histxL",titlex,bins,xmin,xmax);
	TH1F *histx = new TH1F("histx",titlex,bins,xmin,xmax);
	histx->Sumw2();
	chainHeR->Draw("(PriKineR.Q2 / (PriKineR.nu * 2 * 0.9315))>>histxR", cutsR, "E");
	chainHeL->Draw("(PriKineL.Q2 / (PriKineL.nu * 2 * 0.9315))>>histxL", cutsL, "E");
	histx->Add(histxR,histxL);
	histx->Draw();


	// Note: Asymmetry is defined as (Pos - Neg)/(Pos + Neg)
	pad11->cd();
	TString titleAsym = "Beam Asymmetry (%) vs. Bjorken x for Q2 of ";
	titleAsym += Q2;
	cout << "Drawing " << titleAsym << "..." << endl;
	histAsym = histPosHelx->GetAsymmetry(histNegHelx);
	histAsym->Scale(100);
	histAsym->SetTitle(titleAsym);
	histAsym->Draw();

	TString imagename = "Asymmetries/Vertical_Beam_Asymmetry_for_Q2_of_";
	imagename += Q2;
	imagename += ".png";
	c1->Print(imagename);


	cout << "All done!" << endl;


}
示例#6
0
void ana_complete(int nevts=0)
{
    //-----User Settings:------------------------------------------------------
  TString  parAsciiFile   = "all.par";
  TString  prefix         = "evtcomplete";
  TString  input          = "psi2s_Jpsi2pi_Jpsi_mumu.dec"; 
  TString  output         = "ana";
  TString  friend1        = "pid";
  TString  friend2        = "";
  TString  friend3        = "";
  TString  friend4        = "";
  
  // -----   Initial Settings   --------------------------------------------
  PndMasterRunAna *fRun= new PndMasterRunAna();
  fRun->SetInput(input);
  fRun->SetOutput(output);
  fRun->SetFriend1(friend1);
  fRun->SetFriend2(friend2);
  fRun->SetFriend3(friend3);
  fRun->SetFriend4(friend4);
  fRun->SetParamAsciiFile(parAsciiFile);
  fRun->Setup(prefix);
        
	// *** some variables
	int i=0,j=0, k=0, l=0;
	gStyle->SetOptFit(1011);

	fRun->Init(); 
	
        // *** create an output file for all histograms
	TFile *out = TFile::Open(prefix+"_output_ana.root","RECREATE");
	
	// *** create some histograms
	TH1F *hmomtrk    = new TH1F("hmomtrk","track momentum (all)",200,0,5);
	TH1F *hthttrk    = new TH1F("hthttrk","track theta (all)",200,0,3.1415);
	
	TH1F *hjpsim_all = new TH1F("hjpsim_all","J/#psi mass (all)",200,0,4.5);
	TH1F *hpsim_all  = new TH1F("hpsim_all","#psi(2S) mass (all)",200,0,5);
	
	TH1F *hjpsim_lpid = new TH1F("hjpsim_lpid","J/#psi mass (loose pid)",200,0,4.5);
	TH1F *hpsim_lpid  = new TH1F("hpsim_lpid","#psi(2S) mass (loose pid)",200,0,5);
	
	TH1F *hjpsim_tpid = new TH1F("hjpsim_tpid","J/#psi mass (tight pid)",200,0,4.5);
	TH1F *hpsim_tpid  = new TH1F("hpsim_tpid","#psi(2S) mass (tight pid)",200,0,5);
	
	TH1F *hjpsim_trpid = new TH1F("hjpsim_trpid","J/#psi mass (true pid)",200,0,4.5);
	TH1F *hpsim_trpid  = new TH1F("hpsim_trpid","#psi(2S) mass (true pid)",200,0,5);
	
	
	TH1F *hjpsim_ftm = new TH1F("hjpsim_ftm","J/#psi mass (full truth match)",200,0,4.5);
	TH1F *hpsim_ftm  = new TH1F("hpsim_ftm","#psi(2S) mass (full truth match)",200,0,5);
	
	TH1F *hjpsim_nm = new TH1F("hjpsim_nm","J/#psi mass (no truth match)",200,0,4.5);
	TH1F *hpsim_nm  = new TH1F("hpsim_nm","#psi(2S) mass (no truth match)",200,0,5);
	
	TH1F *hjpsim_diff = new TH1F("hjpsim_diff","J/#psi mass diff to truth",100,-2,2);
	TH1F *hpsim_diff  = new TH1F("hpsim_diff","#psi(2S) mass diff to truth",100,-2,2);
	
	
	TH1F *hjpsim_vf   = new TH1F("hjpsim_vf","J/#psi mass (vertex fit)",200,0,4.5);
	TH1F *hjpsim_4cf  = new TH1F("hjpsim_4cf","J/#psi mass (4C fit)",200,0,4.5);
	TH1F *hjpsim_mcf  = new TH1F("hjpsim_mcf","J/#psi mass (mass constraint fit)",200,0,4.5);
	
	TH1F *hjpsi_chi2_vf  = new TH1F("hjpsi_chi2_vf", "J/#psi: #chi^{2} vertex fit",100,0,10);
	TH1F *hpsi_chi2_4c   = new TH1F("hpsi_chi2_4c",  "#psi(2S): #chi^{2} 4C fit",100,0,250);
	TH1F *hjpsi_chi2_mf  = new TH1F("hjpsi_chi2_mf", "J/#psi: #chi^{2} mass fit",100,0,10);
	
	TH1F *hjpsi_prob_vf  = new TH1F("hjpsi_prob_vf", "J/#psi: Prob vertex fit",100,0,1);
	TH1F *hpsi_prob_4c   = new TH1F("hpsi_prob_4c",  "#psi(2S): Prob 4C fit",100,0,1);
	TH1F *hjpsi_prob_mf  = new TH1F("hjpsi_prob_mf", "J/#psi: Prob mass fit",100,0,1);
	
	TH2F *hvpos = new TH2F("hvpos","(x,y) projection of fitted decay vertex",100,-2,2,100,-2,2);
	
	//
	// Now the analysis stuff comes...
	//
	
	
	// *** the data reader object
	PndAnalysis* theAnalysis = new PndAnalysis();
	if (nevts==0) nevts= theAnalysis->GetEntries();
	
	// *** RhoCandLists for the analysis
	RhoCandList chrg, muplus, muminus, piplus, piminus, jpsi, psi2s;
	
	// *** Mass selector for the jpsi cands
	double m0_jpsi = TDatabasePDG::Instance()->GetParticle("J/psi")->Mass();   // Get nominal PDG mass of the J/psi
	RhoMassParticleSelector *jpsiMassSel=new RhoMassParticleSelector("jpsi",m0_jpsi,1.0);
	
	// *** the lorentz vector of the initial psi(2S)
	TLorentzVector ini(0, 0, 6.231552, 7.240065);
	
	// ***
	// the event loop
	// ***
	
	int cntdbltrk=0, cntdblmc=0, cntdblboth=0, cnttrk=0, cnt_dbl_jpsi=0, cnt_dbl_psip=0;
	
	while (theAnalysis->GetEvent() && i++<nevts)
	{
		if ((i%100)==0) cout<<"evt " << i << endl;
				
		// *** Select with no PID info ('All'); type and mass are set 		
		theAnalysis->FillList(chrg,    "Charged");
		theAnalysis->FillList(muplus,  "MuonAllPlus");
		theAnalysis->FillList(muminus, "MuonAllMinus");
		theAnalysis->FillList(piplus,  "PionAllPlus");
		theAnalysis->FillList(piminus, "PionAllMinus");

		// *** momentum and theta histograms
		for (j=0;j<muplus.GetLength();++j) 
		{
			hmomtrk->Fill(muplus[j]->P());
			hthttrk->Fill(muplus[j]->P4().Theta());
		}
		for (j=0;j<muminus.GetLength();++j) 
		{
			hmomtrk->Fill(muminus[j]->P());
			hthttrk->Fill(muminus[j]->P4().Theta());
		}
		
		cnttrk += chrg.GetLength();
		
		int n1, n2, n3;
		
		countDoubles(chrg,n1,n2,n3);
		cntdbltrk  += n1;
		cntdblmc   += n2;
		cntdblboth += n3;		
		
		// *** combinatorics for J/psi -> mu+ mu-
		jpsi.Combine(muplus, muminus);
		
		
		// ***
		// *** do the TRUTH MATCH for jpsi
		// ***
		jpsi.SetType(443);
				
		int nm = 0;
		for (j=0;j<jpsi.GetLength();++j) 
		{
			hjpsim_all->Fill( jpsi[j]->M() );
			
			if (theAnalysis->McTruthMatch(jpsi[j]))
			{ 
				nm++;
				hjpsim_ftm->Fill( jpsi[j]->M() );
			 	hjpsim_diff->Fill( jpsi[j]->GetMcTruth()->M() - jpsi[j]->M() );
			}
			else 
				hjpsim_nm->Fill( jpsi[j]->M() );
		}
		
		if (nm>1) cnt_dbl_jpsi++;
		// ***
		// *** do VERTEX FIT (J/psi)
		// ***
		for (j=0;j<jpsi.GetLength();++j) 
		{
			PndKinVtxFitter vtxfitter(jpsi[j]);	// instantiate a vertex fitter
			vtxfitter.Fit();
			
			double chi2_vtx = vtxfitter.GetChi2();	// access chi2 of fit
			double prob_vtx = vtxfitter.GetProb();	// access probability of fit
			hjpsi_chi2_vf->Fill(chi2_vtx);
			hjpsi_prob_vf->Fill(prob_vtx);			
			
			if ( prob_vtx > 0.01 )				// when good enough, fill some histos
			{
				RhoCandidate *jfit = jpsi[j]->GetFit();	// access the fitted cand
				TVector3 jVtx=jfit->Pos();		// and the decay vertex position
				
				hjpsim_vf->Fill(jfit->M());            
				hvpos->Fill(jVtx.X(),jVtx.Y());
			}
		}
		
		// *** some rough mass selection
		jpsi.Select(jpsiMassSel);
		
		// *** combinatorics for psi(2S) -> J/psi pi+ pi-
		psi2s.Combine(jpsi, piplus, piminus);
		
		
		// ***
		// *** do the TRUTH MATCH for psi(2S)
		// ***
		psi2s.SetType(88888);

		nm = 0;
		for (j=0;j<psi2s.GetLength();++j) 
		{
			hpsim_all->Fill( psi2s[j]->M() );
			
			if (theAnalysis->McTruthMatch(psi2s[j])) 
			{
				nm++;
			 	hpsim_ftm->Fill( psi2s[j]->M() );
			 	hpsim_diff->Fill( psi2s[j]->GetMcTruth()->M() - psi2s[j]->M() );
			}
			else 
				hpsim_nm->Fill( psi2s[j]->M() );
		}			
		if (nm>1) cnt_dbl_psip++;

		
		// ***
		// *** do 4C FIT (initial psi(2S) system)
		// ***
		for (j=0;j<psi2s.GetLength();++j) 
		{
			PndKinFitter fitter(psi2s[j]);	// instantiate the kin fitter in psi(2S)
			fitter.Add4MomConstraint(ini);	// set 4 constraint
			fitter.Fit();		            // do fit
			
			double chi2_4c = fitter.GetChi2();	// get chi2 of fit
			double prob_4c = fitter.GetProb();	// access probability of fit
			hpsi_chi2_4c->Fill(chi2_4c);
			hpsi_prob_4c->Fill(prob_4c);			
			
			if ( prob_4c > 0.01 )			// when good enough, fill some histo
			{
				RhoCandidate *jfit = psi2s[j]->Daughter(0)->GetFit();	// get fitted J/psi
				
				hjpsim_4cf->Fill(jfit->M());
			}
		}		
		
		
		// ***
		// *** do MASS CONSTRAINT FIT (J/psi)
		// ***
		for (j=0;j<jpsi.GetLength();++j) 
		{
			PndKinFitter mfitter(jpsi[j]);		// instantiate the PndKinFitter in psi(2S)
			mfitter.AddMassConstraint(m0_jpsi);	// add the mass constraint
			mfitter.Fit();						// do fit
			
			double chi2_m = mfitter.GetChi2();	// get chi2 of fit
			double prob_m = mfitter.GetProb();	// access probability of fit
			hjpsi_chi2_mf->Fill(chi2_m);
			hjpsi_prob_mf->Fill(prob_m);			
			
			if ( prob_m > 0.01 )				// when good enough, fill some histo
			{
				RhoCandidate *jfit = jpsi[j]->GetFit();	// access the fitted cand
				hjpsim_mcf->Fill(jfit->M());
			}
		}		
		
		
		// ***
		// *** TRUE PID combinatorics
		// ***
		
		// *** do MC truth match for PID type
		SelectTruePid(theAnalysis, muplus);
		SelectTruePid(theAnalysis, muminus);
		SelectTruePid(theAnalysis, piplus);
		SelectTruePid(theAnalysis, piminus);
				
		// *** all combinatorics again with true PID
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_trpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_trpid->Fill( psi2s[j]->M() );
		
		
		// ***
		// *** LOOSE PID combinatorics
		// ***
		
		// *** and again with PidAlgoMvd;PidAlgoStt;PidAlgoDrc and loose selection
		theAnalysis->FillList(muplus,  "MuonLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(muminus, "MuonLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(piplus,  "PionLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_lpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_lpid->Fill( psi2s[j]->M() );
		
		
		// ***
		// *** TIGHT PID combinatorics
		// ***
		
		// *** and again with PidAlgoMvd;PidAlgoStt and tight selection
		theAnalysis->FillList(muplus,  "MuonTightPlus",  "PidAlgoMdtHardCuts");
		theAnalysis->FillList(muminus, "MuonTightMinus", "PidAlgoMdtHardCuts");
		theAnalysis->FillList(piplus,  "PionLoosePlus",  "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		theAnalysis->FillList(piminus, "PionLooseMinus", "PidAlgoMvd;PidAlgoStt;PidAlgoDrc");
		
		jpsi.Combine(muplus, muminus);
		for (j=0;j<jpsi.GetLength();++j) hjpsim_tpid->Fill( jpsi[j]->M() );
		jpsi.Select(jpsiMassSel);
		
		psi2s.Combine(jpsi, piplus, piminus);
		for (j=0;j<psi2s.GetLength();++j) hpsim_tpid->Fill( psi2s[j]->M() );
		
	}
		
	// *** write out all the histos
	out->cd();
	
	hmomtrk->Write();
	hthttrk->Write();
	
	hjpsim_all->Write();
	hpsim_all->Write();
	hjpsim_lpid->Write();
	hpsim_lpid->Write();
	hjpsim_tpid->Write();
	hpsim_tpid->Write();
	hjpsim_trpid->Write();
	hpsim_trpid->Write();
	
	hjpsim_ftm->Write();
	hpsim_ftm->Write();
	hjpsim_nm->Write();
	hpsim_nm->Write();
	
	hpsim_diff->Write();
	hjpsim_diff->Write();
	
	hjpsim_vf->Write();
	hjpsim_4cf->Write();
	hjpsim_mcf->Write();
	
	hjpsi_chi2_vf->Write();
	hpsi_chi2_4c->Write();
	hjpsi_chi2_mf->Write();
			
	hjpsi_prob_vf->Write();
	hpsi_prob_4c->Write();
	hjpsi_prob_mf->Write();
			
	hvpos->Write();
		
	out->Save();
        
	fRun->Finish();
        exit(0);
	
}
示例#7
0
//__________________________________________________________________________
void etaDependence_V2Ana()
{
  gROOT->Macro("/Users/eusmartass/Software/utilities/setStyle.C+");
  gStyle->SetOptFit(0);

 //  TFile *f1 = new TFile("inclusive150_jpsi/InclusiveYield/ep21/xopt21_mbFixedIncl/summary/saved_histo.root");
//   const char* nameoutfile[2] = {"",
// 				"ep21_xopt21_mbFixedIncl"
//   };

//   const char* eventPlane[2] = {"",
// 			       "EP: etHF"
//   };

//   TFile *f1 = new TFile("inclusive150_jpsi/InclusiveYield/ep23/xopt21_bit1/summary/saved_histo.root");
//   const char* nameoutfile[2] = {"",
// 				"ep23_xopt21_bit1"
//   };
  
//   const char* eventPlane[2] = {"",
// 			       "EP: etHFm"
//   };

  TFile *f1 = new TFile("inclusive150_jpsi/InclusiveYield/ep22/xopt21_bit2/summary/saved_histo.root");
  const char* nameoutfile[2] = {"",
				"ep22_xopt21_bit2"
  };
  
  const char* eventPlane[2] = {"",
			       "EP: etHFp"
  };


  const int ncentbins = 2;
  const int nrapbins  = 4;
  const int nptbins   = 3; 
  int    cts[ncentbins]  = {10, 60};
  double raps[nrapbins]  = {0.0, 1.2,  1.6,  2.4};
  double pts[nptbins]    = {3.0, 6.5, 40.0};

  const char* signal[4]   = {"","NSig","NPr","NNp"};
  const char* legend[4]   = {"","J/#psi","Prompt J/#psi","Non-prompt J/#psi"};
  int choseSignal         = 1; // 1:inclusive 2:prompt 3:non-prompt
  const char* chosenSignal= signal[choseSignal];

  // options
  bool bDoDebug        = false;
  bool bSavePlots      = true; 
  int centrality_start = 0;
  int centrality_end   = 1;
 
  int pt_start = 0;
  int pt_end   = 2;
  int nPads    = pt_end-pt_start;  

  TGraphErrors *g[10][10][10];
  double pr[10][10][10], ep[10][10][10], chi[10][10][10], ndf[10][10][10];
  double vals[4];
   
  char gTmp[512];
  char tmp0[512],tmp2[512], tmp3[512], tmp4[512], tmp5[512], tmp6[512];
  double vraps1, vraps2, vpts1, vpts2;
  int vcts1, vcts2;
  
  for(int mcent = centrality_start; mcent < centrality_end; mcent++)
    {
      vcts1 = cts[mcent]; 
      vcts2 = cts[mcent+1];
      cout<<"Centrlality bin: "<<vcts1<<"-"<<vcts2<<endl;
      
      for(int iy = 0; iy < 4; iy+=2)
	{
	  vraps1 = raps[iy];
	  vraps2 = raps[iy+1];
	  cout<<"Rapidity bin: "<<vraps1<<"-"<<vraps2<<endl;
	  if (iy==0) {pt_start=1;}
	  else pt_start=0;
	  cout<<"Pt_start = "<<pt_start<<endl;
	  for(int jpt = pt_start; jpt < pt_end; jpt++)
	    {
	      cout<<" producing the TGraphs : "<<mcent<<" "<<iy<<" "<<jpt<<" "<<endl;
	      
	      sprintf(gTmp,"rap%.1f-%.1f_cent%d-%d_pT%.1f-%.1f_%s",vraps1,vraps2,vcts1,vcts2,pts[jpt],pts[jpt+1],chosenSignal);
	      cout<<"TGraph name : "<<gTmp<<endl;
	      TGraphErrors *pgTemp =  (TGraphErrors*)f1->Get(gTmp);
	      g[mcent][iy][jpt]  = pgTemp;
	      if(!g[mcent][iy][jpt]) {cout<<"Warning: No graph found !!!!"<<endl;continue;}
	      cout<<g[mcent][iy][jpt]<<endl;
	      double b[4];
	      GetV2(g[mcent][iy][jpt], b);
	      
	      pr[mcent][iy][jpt]  = b[0];
	      ep[mcent][iy][jpt]  = b[1];
	      chi[mcent][iy][jpt] = b[2];
	      ndf[mcent][iy][jpt] = b[3];
	      
	    }//pt bin loop
	}//rapidity loop
    }//centrlaity loop
  
  // #############################  Drawing: 
  TLatex *lt1 = new TLatex();
  lt1->SetNDC();
  
  for(int mcent = centrality_start; mcent < centrality_end; mcent++)
    {
      vcts1  = cts[mcent]; 
      vcts2  = cts[mcent+1];
      cout<<"Canvas Centrality: "<<vcts1<<"-"<<vcts2<<endl;

      TCanvas *pc1 = new TCanvas("pc1",Form("pcV2_%d-%d",vcts1,vcts2),0,0,1200,750);
      TH1F    *pp  = new TH1F("pp",
			      Form(";|#phi_{J/#psi} - #Psi_{RP}|;#frac{1}{N_{total J/#psi}} #frac{dN}{d#phi}"),
			      4,0,TMath::PiOver2());
      pp->SetMaximum(1.2);
      pp->SetMinimum(0.2);
      makeMultiPanelCanvas(pc1,nPads,2,0.0,0.0,0.2,0.15,0.02);
           
      int ind = 0;
      for(int ky = 0; ky < 4; ky+=2)
	{
	  vraps1 = raps[ky];
	  vraps2 = raps[ky+1];
	  cout << "Canvas Rapidity = "<< vraps1 << "\t"<<vraps2<<endl;
	  //	  if (ky==0) pt_start=1;
	  for(int lpt = pt_start; lpt < pt_end; lpt++)
	    {
	      pc1->cd(ind+1);
	      vpts1 = pts[lpt]; 
	      vpts2 = pts[lpt+1];
	      pp->Draw();
	      ind++;
	      	      
	      lt1->SetTextSize(0.05);
	      if(ind == 1) 
		{
		  lt1->DrawLatex(0.75,0.8,Form("|y| < %.1f",vraps2));       // rapidity
		  lt1->DrawLatex(0.25,0.3,Form("%d - %d %%",vcts1, vcts2));
		  lt1->DrawLatex(0.25,0.15,Form("%s",eventPlane[1]));
		}
	      if(ind == 3) 
		{
		  lt1->DrawLatex(0.75,0.8,Form("%.1f < |y| < %.1f",vraps1,vraps2));       // rapidity	
		}
	      if(!g[mcent][ky][lpt]) 
		{
		  cout<<"No graph! continued !!!!"<<endl;
		  continue;
		}
	      cout<<"#### Drawing: cent:"<<vcts1<<"-"<<vcts2<<"\t rapidity"<<vraps1<<"-"<<vraps2<<"\t pt"<<vpts1<<"-"<<vpts2<<endl;
	      g[mcent][ky][lpt]->Draw("pz");
	      if(ind<3)
		{// drapwing v2 value and pt
		  lt1->DrawLatex(0.1,0.15,Form("v_{2}: %.4f #pm %.4f (#chi^{2} / ndof: %.3f / %.0f)", pr[mcent][ky][lpt], ep[mcent][ky][lpt], chi[mcent][ky][lpt], ndf[mcent][ky][lpt]));
		  lt1->DrawLatex(0.1,0.07,Form("%.1f < p_{T} <%.1f", vpts1, vpts2)); 
		} else if(ind==4) 
		{
		  lt1->DrawLatex(0.1,0.3,Form("v_{2}: %.4f #pm %.4f (#chi^{2} / ndof: %.3f / %.0f)", pr[mcent][ky][lpt], ep[mcent][ky][lpt], chi[mcent][ky][lpt], ndf[mcent][ky][lpt]));
		  lt1->DrawLatex(0.1,0.22,Form("%.1f < p_{T} <%.1f", vpts1, vpts2)); 
		} else 
		{
		  lt1->DrawLatex(0.25,0.3,Form("v_{2}: %.4f #pm %.4f (#chi^{2} / ndof: %.3f / %.0f)", pr[mcent][ky][lpt], ep[mcent][ky][lpt], chi[mcent][ky][lpt], ndf[mcent][ky][lpt]));
		  lt1->DrawLatex(0.25,0.22,Form("%.1f < p_{T} <%.1f", vpts1, vpts2));
		}
	    }// pt loop
	}//y bin loop
  
     //_______ stuff to write
  pc1->cd(1);
  TLatex *tex1 = new TLatex(0.25,0.95,"CMS Preliminary");
  tex1->SetNDC();
  tex1->SetTextAlign(13);
  tex1->SetTextFont(43);
  tex1->SetTextSize(23);
  tex1->SetLineWidth(1);
  tex1->Draw();

  TLatex *tex2 = new TLatex(0.25,0.89,"PbPb  #sqrt{s_{NN}} = 2.76 TeV");
  tex2->SetNDC();
  tex2->SetTextAlign(13);
  tex2->SetTextFont(43);
  tex2->SetTextSize(18);
  tex2->SetLineWidth(2);
  tex2->Draw();

  TLatex *tex3 = new TLatex(0.25,0.83,"L_{int} = 150 #mub^{-1}");
  tex3->SetNDC();
  tex3->SetTextAlign(13);
  tex3->SetTextFont(43);
  tex3->SetTextSize(18);
  tex3->SetLineWidth(2);
  tex3->Draw();

  lt1->DrawLatex(0.75,0.25,Form("%s",legend[choseSignal]));  // what signal is
  if(bSavePlots)
    {
      pc1->SaveAs(Form("%s_%s_Jpsi_%d_%d_150mub.png",chosenSignal,nameoutfile[1],vcts1,vcts2));
      pc1->SaveAs(Form("%s_%s_Jpsi_%d_%d_150mub.pdf",chosenSignal,nameoutfile[1],vcts1,vcts2));
      
      pc1->Clear();
    }
    }// centrality loop

  //_______________ SUMMARY!!!!
  TCanvas *c2 = new TCanvas("c2","c2");
  // makeMultiPanelCanvas(c2,1,1,0.0,0.0,0.2,0.15,0.02);
  
  double ptBinsFwd[2]      = {4.75, 23.5};
  double ptErrsFwd[3]      = {0.0, 0.0};
  double ptBinsBar[2]      = {23.5};
  double ptErrsBar[2]      = {0.0};

  TH1F *hPad2 = new TH1F("hPad2",";p_{T};Uncorrected v2;",1,0,40);
  hPad2->SetMaximum(0.3);
  hPad2->SetMinimum(-0.3);
  TLegend *leg1 = new TLegend(0.2,0.75,0.45,0.9);
  leg1->SetFillColor(0);
  c2->cd(1);
      
  // [centrality][rapidity][pt]
  double v2PtBarr[1]    = {pr[0][0][1]};
  double v2PtBarrErr[1] = {ep[0][0][1]};

  double v2PtForw[2]    = {pr[0][2][0], pr[0][2][1]};  
  double v2PtForwErr[2] = {ep[0][2][0], ep[0][2][1]};
  
  TGraphErrors *gPtBarr = new TGraphErrors(1, ptBinsBar, v2PtBarr, ptErrsBar, v2PtBarrErr);  
  TGraphErrors *gPtForw = new TGraphErrors(2, ptBinsFwd, v2PtForw, ptErrsFwd, v2PtForwErr);  
  gPtBarr->SetMarkerStyle(20);
  gPtBarr->SetMarkerSize(1.2);
  gPtBarr->SetMarkerColor(kBlue+2);
  
  gPtForw->SetMarkerStyle(21);
  gPtForw->SetMarkerSize(1.2);
  gPtForw->SetMarkerColor(kRed+2);
  
  hPad2->Draw();
  gPtBarr->Draw("p");
  gPtForw->Draw("p");
  c2->Update();
 
  leg1->AddEntry(gPtBarr,"|y| < 1.2","P");
  leg1->AddEntry(gPtForw,"1.6 < |y| < 2.4","P");
  lt1->DrawLatex(0.7,0.15,Form("%s",eventPlane[1]));
  lt1->SetTextSize(0.06);
  lt1->DrawLatex(0.7,0.25,Form("%d - %d %%",cts[0],cts[1]));


  //_______ stuff to write
  leg1->Draw("same");
 TLatex *tex4 = new TLatex(0.65,0.93,"CMS Preliminary");
  tex4->SetNDC();
  tex4->SetTextAlign(13);
  tex4->SetTextFont(43);
  tex4->SetTextSize(23);
  tex4->SetLineWidth(1);
  tex4->Draw();

  TLatex *tex5 = new TLatex(0.65,0.87,"PbPb  #sqrt{s_{NN}} = 2.76 TeV");
  tex5->SetNDC();
  tex5->SetTextAlign(13);
  tex5->SetTextFont(43);
  tex5->SetTextSize(18);
  tex5->SetLineWidth(2);
  tex5->Draw();

  TLatex *tex6 = new TLatex(0.65,0.81,"L_{int} = 150 #mub^{-1}");
  tex6->SetNDC();
  tex6->SetTextAlign(13);
  tex6->SetTextFont(43);
  tex6->SetTextSize(18);
  tex6->SetLineWidth(2);
  tex6->Draw();
  lt1->DrawLatex(0.8,0.6,Form("%s",legend[choseSignal]));  // what signal is
  c2->Update();
  if(bSavePlots)
    {
      c2->SaveAs(Form("%s_jpsi_%s_v2_y.png",chosenSignal,nameoutfile[1]));
      c2->SaveAs(Form("%s_jpsi_%s_v2_y.pdf",chosenSignal,nameoutfile[1]));
    }
 
}
示例#8
0
void ootpu_comparison(TString files, TString var, TString title, int nbins, float low, float high, TString comments="") {

  TChain* chain = new TChain("reduced_tree");
  chain->Add(files);

  TH1::SetDefaultSumw2();

  TH1F* hA = new TH1F("hA",title, nbins, low, high);
  TH1F* hB = new TH1F("hB",title, nbins, low, high);
  TH1F* hC = new TH1F("hC",title, nbins, low, high);
  TH1F* hD = new TH1F("hD",title, nbins, low, high);
  hA->SetStats(0);
  hA->GetYaxis()->SetLabelSize(0.04);
  //hA->GetYaxis()->SetTitleOffset(1.3);
  hA->GetXaxis()->SetTitleOffset(1.1);
  hA->GetXaxis()->SetTitleFont(132);
  hA->GetXaxis()->SetTitleSize(0.042);
  hA->GetXaxis()->SetLabelSize(0.04);
  hA->SetLineWidth(2);

  //  hA->StatOverflows(true);
  //  hB->StatOverflows(true);
  //  hC->StatOverflows(true);
  //  hD->StatOverflows(true);

  int n1(0), n2(0), n3(0), n4(0), n5(0);
  if (files.Contains("20bx25")) {
    n1=5;
    n2=17;
    n3=21;
    n4=25;
    n5=40;
  }
  else if (files.Contains("S14")) {
    n1=0;
    n2=25;
    n3=40;
    n4=55;
    n5=120;
  }
  else { // default: 8 TeV scenario
    n1=0;
    n2=15;
    n3=22;
    n4=32;
    n5=70;
  }


  TString mu("num_gen_muons==1&&muon_reco_match>=0");
  //if (files.Contains("PU_S10")) {
  TString cuts = Form("(%s)&&(eoot_pu>=%d&&eoot_pu<%d)",mu.Data(),n1,n2);
  cout << "Cuts: " << cuts.Data() << endl;
  chain->Project("hA", var, cuts);
  cuts = Form("(%s)&&(eoot_pu>=%d&&eoot_pu<%d)",mu.Data(),n2,n3);
  cout << "Cuts: " << cuts.Data() << endl;
  chain->Project("hB", var, cuts);
  cuts = Form("(%s)&&(eoot_pu>=%d&&eoot_pu<%d)",mu.Data(),n3,n4);
  cout << "Cuts: " << cuts.Data() << endl;
  chain->Project("hC", var, cuts);
  cuts = Form("(%s)&&(eoot_pu>=%d)",mu.Data(),n4);
  cout << "Cuts: " << cuts.Data() << endl;
  chain->Project("hD", var, cuts);
  // }
  // else {
  //  }
  
  float avg1(hA->GetMean());
  float avg2(hB->GetMean());
  float avg3(hC->GetMean());
  float avg4(hD->GetMean());

  hA->Scale(1/hA->Integral());
  hB->Scale(1/hB->Integral());
  hC->Scale(1/hC->Integral());
  hD->Scale(1/hD->Integral());

  hA->SetLineColor(1);
  hB->SetLineColor(2);
  hC->SetLineColor(3);
  hD->SetLineColor(4);

  hA->SetLineWidth(2);
  hB->SetLineWidth(2);
  hC->SetLineWidth(2);
  hD->SetLineWidth(2);

  TCanvas* c1 = new TCanvas();
  float max = TMath::Max(hA->GetMaximum(), hB->GetMaximum());
  if (hC->GetMaximum()>max) max = hC->GetMaximum();
  if (hD->GetMaximum()>max) max = hD->GetMaximum();

  hA->SetMaximum(max*1.1);
  hA->Draw("e1");
  hB->Draw("e1,same");
  hC->Draw("e1,same");
  hD->Draw("e1,same");

  TLegend* leg = new TLegend(0.42,0.6,0.9,0.9);
  leg->SetFillStyle(0);
  char label[1000];
  sprintf(label,"%d#leqEarly Ints.<%d (#mu=%3.3f)",n1,n2,avg1);
  leg->AddEntry(hA,label,"lp");
  sprintf(label,"%d#leqEarly Ints.<%d (#mu=%3.3f)",n2,n3,avg2);
  leg->AddEntry(hB,label,"lp");
  sprintf(label,"%d#leqEarly Ints.<%d (#mu=%3.3f)",n3,n4,avg3);
  leg->AddEntry(hC,label,"lp");
  sprintf(label,"Early Ints.>%d (#mu=%3.3f)",n4,avg4);
  leg->AddEntry(hD,label,"lp");
  // leg->Draw();

  TString plotTitle ="relIso_vs_OOTPU_"+var+comments+".pdf";
  c1->Print(plotTitle);

  cout << "Rejection rates" << endl;
  Double_t left(0.), lerror(0.), right(0.), rerror(0.);
  left = hA->IntegralAndError(1,12,lerror);
  right = hA->IntegralAndError(13,31,rerror);
  float rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  printf("bin1: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  left = hB->IntegralAndError(1,12,lerror);
  right = hB->IntegralAndError(13,31,rerror);
  rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  printf("bin2: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  left = hC->IntegralAndError(1,12,lerror);
  right = hC->IntegralAndError(13,31,rerror);
  rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  printf("bin3: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  left = hD->IntegralAndError(1,12,lerror);
  right = hD->IntegralAndError(13,31,rerror);
  rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  printf("bin4: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
}
示例#9
0
void PlotDrmCorr()
{
  gROOT->LoadMacro("$LOCAL/include/TUntilsOpHisto.h");
  gROOT->LoadMacro("$LOCAL/include/TUntilsAliFigs.h");
  gROOT->LoadMacro("$LOCAL/include/TUntilsPlotStd.h"); SetStyle();

 const TString sJetTag = "120<#it{p}_{T,jet}<150 GeV/#it{c}";
//=============================================================================

  TFile *file = TFile::Open("data/mass/AnalysisOutputs_Dsm_py8_JetR05_SjeR01.root", "READ");
  TH2D *h5py8 = (TH2D*)file->Get("hDfrDdm120"); h5py8->SetName("h5py8"); h5py8->SetDirectory(0);
  file->Close();

  file = TFile::Open("data/mass/AnalysisOutputs_Dsm_qpy_JetR05_SjeR01.root", "READ");
  TH2D *h5qpy = (TH2D*)file->Get("hDfrDdm120"); h5qpy->SetName("h5qpy"); h5qpy->SetDirectory(0);
  file->Close();

  file = TFile::Open("data/mass/AnalysisOutputs_Dsm_med_JetR05_SjeR01.root", "READ");
  TH2D *h5med = (TH2D*)file->Get("hDfrDdm120"); h5med->SetName("h5med"); h5med->SetDirectory(0);
  file->Close();


  file = TFile::Open("data/mass/AnalysisOutputs_Dsm_py8_JetR04_SjeR01.root", "READ");
  TH2D *h4py8 = (TH2D*)file->Get("hDfrDdm120"); h4py8->SetName("h4py8"); h4py8->SetDirectory(0);
  file->Close();

  file = TFile::Open("data/mass/AnalysisOutputs_Dsm_qpy_JetR04_SjeR01.root", "READ");
  TH2D *h4qpy = (TH2D*)file->Get("hDfrDdm120"); h4qpy->SetName("h4qpy"); h4qpy->SetDirectory(0);
  file->Close();

  file = TFile::Open("data/mass/AnalysisOutputs_Dsm_med_JetR04_SjeR01.root", "READ");
  TH2D *h4med = (TH2D*)file->Get("hDfrDdm120"); h4med->SetName("h4med"); h4med->SetDirectory(0);
  file->Close();
//=============================================================================

  const Double_t dBin[] = { 0., 0.1, 0.3, 0.5, 0.8, 1.2 };
  const Int_t nBin = sizeof(dBin) / sizeof(Double_t) -1;

  h5py8->RebinX(50); h4py8->RebinX(50);
  h5qpy->RebinX(50); h4qpy->RebinX(50);
  h5med->RebinX(50); h4med->RebinX(50);

  TH1D *h5py8M = SetRMS(h5py8,"h5py8M"); TH1D *h4py8M = SetRMS(h4py8,"h4py8M");
  TH1D *h5qpyM = SetRMS(h5qpy,"h5qpyM"); TH1D *h4qpyM = SetRMS(h4qpy,"h4qpyM");
  TH1D *h5medM = SetRMS(h5med,"h5medM"); TH1D *h4medM = SetRMS(h4med,"h4medM");

  TGraph *g5py8 = new TGraph(h5py8M); TGraph *g4py8 = new TGraph(h4py8M);
  TGraph *g5qpy = new TGraph(h5qpyM); TGraph *g4qpy = new TGraph(h4qpyM);
  TGraph *g5med = new TGraph(h5medM); TGraph *g4med = new TGraph(h4medM);
//=============================================================================

  TH1F    *hfm = 0;
  TCanvas *can = 0;
  TLegend *leg = 0;
  TLatex  *tex = 0;
  TLine  *line = 0;

  const Float_t dflx = 0.2, dfux = 1.;
  const Float_t dfly = 2., dfuy = 15.;

  const Float_t dlsx = 0.05, dlsy = 0.05;
  const Float_t dtsx = 0.06, dtsy = 0.06;
  const Float_t dtox = 1.10, dtoy = 1.00;

  const TString stnx = "#it{R}(sj^{1st},sj^{2nd})";
  const TString stny = "#sigma(m_{jet}-m_{sj}) (GeV/#it{c}^{2})";

  TH1D *hSE = new TH1D("hSE", "", 10., 0., 10.);
  hSE->SetLineWidth(2);
  hSE->SetLineColor(wcl[0]);
  hSE->SetMarkerStyle(wmk[0]);
  hSE->SetMarkerColor(wcl[0]);

  TH1D *hME = new TH1D("hME", "", 10., 0., 10.);
  hME->SetLineWidth(2);
  hME->SetLineColor(wcl[0]);
  hME->SetMarkerStyle(wmk[2]);
  hME->SetMarkerColor(wcl[0]);
//=============================================================================

  can = MakeCanvas("Jet5py8DrmRMS"); can->SetGridx(); can->SetGridy();
  hfm = can->DrawFrame(dflx, dfly, dfux, dfuy); SetupFrame(hfm, dlsx, dlsy, dtsx, dtsy, dtox, dtoy, stnx, stny);
  hfm->GetXaxis()->SetNdivisions(510);
  hfm->GetYaxis()->SetNdivisions(510);

  DrawGraph(g5py8, wcl[3], "C");
  DrawGraph(g5qpy, wcl[1], "C");
  DrawGraph(g5med, wcl[5], "C");

  leg = new TLegend(0.62, 0.64, 0.98, 0.88); SetupLegend(leg);
  leg->AddEntry(g5py8, "PYTHIA 8", "L")->SetTextSizePixels(24);
  leg->AddEntry(g5qpy, "Q-PYTHIA", "L")->SetTextSizePixels(24);
  leg->AddEntry(g5med, "JEWEL+PYTHIA", "L")->SetTextSizePixels(24);
  leg->Draw();

  tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSizePixels(24);
  tex->DrawLatex(0.16, 0.92, "2.76 TeV, Jet #it{R}=0.5, anti-#it{k}_{T}, |#eta_{jet}|<1");
  tex->DrawLatex(0.16, 0.84, sJetTag.Data());
  CanvasEnd(can);
//=============================================================================

  can = MakeCanvas("Jet4py8DrmRMS"); can->SetGridx(); can->SetGridy();
  hfm = can->DrawFrame(dflx, dfly, dfux, dfuy); SetupFrame(hfm, dlsx, dlsy, dtsx, dtsy, dtox, dtoy, stnx, stny);
  hfm->GetXaxis()->SetNdivisions(510);
  hfm->GetYaxis()->SetNdivisions(510);

  DrawGraph(g4py8, wcl[3], "C");
  DrawGraph(g4qpy, wcl[1], "C");
  DrawGraph(g4med, wcl[5], "C");

  leg = new TLegend(0.62, 0.64, 0.98, 0.88); SetupLegend(leg);
  leg->AddEntry(g4py8, "PYTHIA 8", "L")->SetTextSizePixels(24);
  leg->AddEntry(g4qpy, "Q-PYTHIA", "L")->SetTextSizePixels(24);
  leg->AddEntry(g4med, "JEWEL+PYTHIA", "L")->SetTextSizePixels(24);
  leg->Draw();

  tex = new TLatex();
  tex->SetNDC();
  tex->SetTextSizePixels(24);
  tex->DrawLatex(0.16, 0.92, "2.76 TeV, Jet #it{R}=0.4, anti-#it{k}_{T}, |#eta_{jet}|<1");
  tex->DrawLatex(0.16, 0.84, sJetTag.Data());
  CanvasEnd(can);
//=============================================================================



  return;
}
示例#10
0
void PlotBackground(string filename)
{
  heatmapgradient();
  gStyle->SetOptStat(0);
  TFile* file = TFile::Open(filename.c_str());
  TTree* tree = (TTree*)file->Get("DecayTree");
  TCanvas* can[4];
  string bra[4] = {"cos_theta1"
                  ,"cos_theta2"
                  ,"Phi_angle"
                  ,"KK_M"};
  string tit[4] = {"cos#theta_{1}"
                  ,"cos#theta_{2}"
                  ,"#Phi"
                  ,"m(K^{#plus}K^{#minus})"};
  string opt[4] = {"10,-1,1"
                  ,"10,-1,1"
                  ,"10,-3.142,3.142"
                  ,"10,988,1800"};
  for(int i = 0; i < 4; i++)
  {
    can[i] = new TCanvas(("projection"+bra[i]).c_str(),"",500,500);
    can[i]->Draw();
    can[i]->cd();
    tree->Draw((bra[i]+">>htemp("+opt[i]+")").c_str());
    TH1F* graph = (TH1F*)can[i]->GetPrimitive("htemp");
    graph->SetTitle("");
    graph->GetXaxis()->SetTitle(tit[i].c_str());
    graph->SetMinimum(0);
    can[i]->SaveAs((bra[i]+".pdf").c_str());
  }
  TCanvas* canv[6];
  string comb[6] = {"cos_theta1:cos_theta2"
                   ,"cos_theta1:Phi_angle"
                   ,"cos_theta2:Phi_angle"
                   ,"Phi_angle:KK_M"
                   ,"cos_theta1:KK_M"
                   ,"cos_theta2:KK_M"};
  string opts[6] = {"5,-1,1,5,-1,1"
                   ,"5,-3.142,3.142,5,-1,1"
                   ,"5,-3.142,3.142,5,-1,1"
                   ,"5,988,1800,5,-3.142,3.142"
                   ,"5,988,1800,5,-1,1"
                   ,"5,988,1800,5,-1,1"};
  string ytit[6] = {"cos#theta_{1}"
                   ,"cos#theta_{1}"
                   ,"cos#theta_{2}"
                   ,"#Phi"
                   ,"cos#theta_{1}"
                   ,"cos#theta_{2}"};
  string xtit[6] = {"cos#theta_{2}"
                   ,"#Phi"
                   ,"#Phi"
                   ,"m(K^{#plus}K^{#minus})"
                   ,"m(K^{#plus}K^{#minus})"
                   ,"m(K^{#plus}K^{#minus})"};
  for(int lego = 0; lego < 2; lego++)
  {
    for(int i = 0; i < 6; i++)
    {
      canv[i] = new TCanvas(("projection"+comb[i]).c_str(),"",500,500);
      canv[i]->Draw();
      canv[i]->cd();
      tree->Draw((comb[i]+">>htemp("+opts[i]+")").c_str(),"", (lego ? "LEGO" : "COLZ"));
      TH2F* graph = (TH2F*)canv[i]->GetPrimitive("htemp");
      graph->SetTitle("");
      graph->GetXaxis()->SetTitle(xtit[i].c_str());
      graph->GetYaxis()->SetTitle(ytit[i].c_str());
      graph->SetMinimum(0);
      cout << "Fetched graph" << endl;
      string outname = comb[i];
      std::replace(outname.begin(),outname.end(), ':', '-');
      canv[i]->SaveAs((outname + (lego ? "lego.pdf" : ".pdf")).c_str());
    }
  }
  
  
//  tree->Draw();
}
示例#11
0
void EvtSel_Q2Pmiss(){

  Styles style2; style2.setPadsStyle(2); style2.applyStyle();

  TString NameTrees[3] = {"AWG82/ntuples/small/RAll_RunAll.root", 
			  "AWG82/ntuples/small/uds_RunAll.root", "AWG82/ntuples/small/ccbar_RunAll.root"};
  TChain gen("ntp1"), cont("ntp1");
  gen.Add(NameTrees[0]);
  for(int t=1; t<3; t++) cont.Add(NameTrees[t]);
  double totMCB = 0, totuds = 0, totccbar = 0, totdata = 0, totOffdata = 0;
  getNumberB(NameTrees[0], "All", totMCB, totdata, totuds, totccbar, totOffdata);
  double wuds = totMCB/totuds*2.09/1.05;     

  TH1F *hCount = new TH1F("hCount","",100,-4,12);
  gen.Draw("candM2>>hCount","weight");
  double nTotal = hCount->Integral();
  cont.Draw("candM2>>hCount","weight");
  nTotal += hCount->Integral()*wuds;

  TLine line; line.SetLineStyle(2); line.SetLineColor(28); line.SetLineWidth(2);
  TArrow arrow; arrow.SetLineColor(28); arrow.SetFillColor(28); arrow.SetLineWidth(2);
  TCanvas can("can","Pmiss and q2 cuts");
  can.Divide(2,1); TPad *cPad = (TPad *)can.cd(1);
  int bins[] = {42,40}, colors[2][4] = {{8,4,1,3},{8,2,4,1}};
  double xrange[2][2] = {{0,4.2},{-3,13}}, yield[2][4], maxi[] = {-99,-99};
  TString Variable[] = {"candPMiss","candQ2"};
  TString labels[2][4] = {{"Signal (", "Normaliz. (","Had. bkg. (",""},
 			  {"Signal (", "D l #nu (", "D* l #nu (", "Bkg. ("}};
//   TString labels[2][4] = {{"Signal", "Normaliz.","Had. Bkg.",""},
// 			  {"Signal", "D l #nu", "D* l #nu", "Bkg."}};
  TString cuts[2][4] = {{"(candType<3&&MCType>4&&MCType<7||candType>2&&MCType>10&&MCType<13)*weight",
			 "(candType<3&&MCType>0&&MCType<5||candType>2&&MCType>6&&MCType<11)*weight",
			 "(MCType==0&&MCCombmode==12)*weight", ""},
			{"(candType<3&&MCType>4&&MCType<7||candType>2&&MCType>10&&MCType<13)*weight",
			 "(candType<3&&(MCType==1||MCType==3)||candType>2&&(MCType==7||MCType==9))*weight",
			 "(candType<3&&(MCType==2||MCType==4)||candType>2&&(MCType==8||MCType==10))*weight",
			 "(!(candType<3&&MCType>0&&MCType<7||candType>2&&MCType>6&&MCType<13))*weight"}};
  double legW = 0.4, legH = 0.225;
  double legX = 1-style2.PadRightMargin-0.02, legY = 1-style2.PadTopMargin-0.02;
  TLegend *leg[2];
  leg[0] = new TLegend(legX-legW, legY-legH, legX, legY);
  legW = 0.24; legH = 0.285; legX = 0.47;
  leg[1] = new TLegend(legX-legW, legY-legH, legX, legY);
  TH1F* h[2][4];
  for(int pad=0; pad<2; pad++){
    leg[pad]->SetTextSize(style2.LabelSize); leg[pad]->SetFillColor(0); 
    leg[pad]->SetTextFont(style2.nFont);  leg[pad]->SetBorderSize(0);
    for(int i=0; i<4; i++) {
      if(pad==0 && i==3) continue;
      TString hname = "h"; hname += pad; hname += i;
      h[pad][i] = new TH1F(hname,"",bins[pad],xrange[pad][0],xrange[pad][1]);
      h[pad][i]->SetLineWidth(2);  h[pad][i]->SetLineColor(colors[pad][i]);
      TString vari = Variable[pad]; vari += ">>"; vari += hname;
      gen.Draw(vari,cuts[pad][i]);
      if(i==3){
	hname = "hCont"; hname += pad; hname += i;
	TH1F *hCont = new TH1F(hname,"",bins[pad],xrange[pad][0],xrange[pad][1]);
	TString vari = Variable[pad]; vari += ">>"; vari += hname;
	cont.Draw(vari,cuts[pad][i]);
	hCont->Scale(wuds);
	h[pad][i]->Add(hCont);
	hCont->Delete();
      }
      yield[pad][i] = h[pad][i]->Integral();
      h[pad][i]->Scale(1000/h[pad][i]->Integral());
      if(h[pad][i]->GetMaximum()>maxi[pad]) maxi[pad] = h[pad][i]->GetMaximum();
      labels[pad][i] += RoundNumber(yield[pad][i]*100,0,nTotal); labels[pad][i] += "%)";
      leg[pad]->AddEntry(h[pad][i],labels[pad][i]);
    }
    h[pad][0]->SetMaximum(maxi[pad]*1.22);
  }
  h[0][0]->Draw();
  style2.fixYAxis(h[0][0],cPad);
  style2.setTitles(h[0][0],"|p_{miss}| (GeV)","Entries/(100 MeV)","a)");
  h[0][1]->Draw("same");h[0][2]->Draw("same");
  leg[0]->Draw();
  line.DrawLine(0.2,h[0][0]->GetMinimum(), 0.2,maxi[0]/1.45);
  arrow.DrawArrow(0.2,maxi[0]/1.65,0.5,maxi[0]/1.65,0.01,"|>");


  cPad = (TPad *)can.cd(2);
  h[1][0]->Draw();
  style2.fixYAxis(h[1][0],cPad);
  style2.setTitles(h[1][0],"q^{2} (GeV^{2})","Entries/(0.4 GeV^{2})","b)");
  h[1][1]->Draw("same"); h[1][2]->Draw("same"); h[1][3]->Draw("same");
  leg[1]->Draw();
  line.DrawLine(4,h[1][0]->GetMinimum(), 4,maxi[1]/1.45);
  arrow.DrawArrow(4,maxi[1]/1.65,5.4,maxi[1]/1.65,0.01,"|>");

  TString pName = "public_html/EvtSel_Q2Pmiss.eps"; 
  can.SaveAs(pName);
  for(int pad=0; pad<2; pad++){
    leg[pad]->Delete();
    for(int i=0; i<4; i++){
      if(pad==0 && i==3) continue;
      h[pad][i]->Delete();
    }
  }
  hCount->Delete();
}
示例#12
0
void EflowCASTOR()
{

  NCanvas(1,2,"data");

  TH1F * HDat;
  TH1F * HZ2;

  //  TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root");
  TFile *fzee = new TFile("ZDiffOutputfile.root");
  // TFile *fzee = new TFile("ZDiffOutputfile.root");
  HDat  =  (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_DATA");
  HZ2  =  (TH1F*)fzee->Get("NVTX1_EnergyCastorModule_Z2PY6");
  data->cd(1);
  NHSetMarker(HDat,2,20,0.8);
  HDat->SetMinimum(10);
  HDat->Draw();
  NStat(HDat,0);
  NSetTitle(HDat,"CASTOR Modules", "Entries");

  HDat->SetTitle("CASTOR Module Energy 2010");
  HZ2->Draw("SAME HIST");
  NHSetMarker(HDat,2,20,0.4);
  TLegend *legend = new TLegend(0.6,0.7,0.9,0.8);
  legend->SetTextFont(72);
  legend->SetTextSize(0.06);
  legend->SetBorderSize(0);


  legend->AddEntry(HDat,"Data2010","p");
  legend->AddEntry(HZ2,"Z2","l");
  legend->Draw();


  TH1F * Hra = (TH1F * ) HDat->Clone();
  //  Hra->GetXaxis->SetRange(0,12);
  NStat(Hra,0);
  NHSetMarker(Hra,4,20,0.8);
  Hra->SetMinimum(1);
  Hra->Divide(HZ2);
  NLogAxis(0,0);
  data->cd(2);
  Hra->Draw();
  Hra->SetTitle("Ratio DATA/MC");
  Hra->Fit("pol0");
  NSetTitle(Hra,"CASTOR Modules", "Ratio");
  NLogAxis(0,1);

}
示例#13
0
void FindMCPUWeight(){

  NCanvas(1,2,"data");
  
  TH1F * Data;
  TH1F * DataVtx;
  TH1F * PytZ2;
  TH1F * PytZ2_Vis;
  
  TFile *fzee = new TFile("ZDiffOutputfile.root");
  
  Data  =  (TH1F*)fzee->Get("NoCuts_InstLumiPerBx_DATA10");
  DataVtx  =  (TH1F*)fzee->Get("NoCuts_GoodVtx_DATA10");  
  PytZ2  =  (TH1F*)fzee->Get("Gen_PUVtx_Z2PY6");
  PytZ2_Vis  =  (TH1F*)fzee->Get("NoCuts_GoodVtx_Z2PY6");
  
  Float_t DataInt = Data->Integral(); 
  
  data->cd(1);
  
  NSetTitle(Data,"Single bunch luminosity [10^{30}cm^{-2}s^{-1}]","Entries");
  NSetLabelSize(Data);
  NSetTitleSize(Data,0.8,0.8,0.06);
  NStat(Data,0);
  Data->SetTitle("Z Luminosity");
  NHSetMarker(Data);
  Data->Draw();
  
  
  Int_t const NRS = 1000;
  //  Float_t Sigma = 0.0485;
  Float_t Sigma = 0.073;
  Int_t const MaxVtxInEvent = 25;
  Float_t sigma_NSD =  Sigma*pow(10,-24);
  char hname[100]; 
  sprintf(hname,"Pois_Theory");
  gDirectory->Delete(hname);
  TH1F * pois_theory  = new TH1F(hname,hname,MaxVtxInEvent,-0.5,MaxVtxInEvent-0.5); // Pois hystograms
  pois_theory->Sumw2();
  
  for (Int_t NL = 1; NL<=NRS; NL++)
    {
      
      Double_t LumiR = Data->GetRandom();
      
      for (Int_t p=0;p<MaxVtxInEvent;p++)
	{
	  
	  Float_t Lum_bunch = (LumiR*pow(10,30)/11346)*sigma_NSD ;
	  Float_t pois_prob = pow(Lum_bunch,p) * exp(-Lum_bunch)/TMath::Factorial(p) ;		
	  pois_theory->Fill(p+0.01,pois_prob);
	  
	}
    }
  
  if (pois_theory->GetEntries() !=0)
    {
      pois_theory->Scale(DataInt/NRS);
      data->cd(2);
      NSetTitle(pois_theory,"# PU Vertexes in event","Fraction");
      NSetLabelSize(pois_theory);
      NSetTitleSize(pois_theory,0.8,0.8,0.06);
      NStat(pois_theory,0);
      pois_theory->SetTitle("MC PU generated vertex distribution");
      //	    pois_theory->SetTitleSize(1.);
      NHSetMarker(pois_theory);
      DataVtx->Draw();  
      pois_theory->Draw("SAME HIST");
      
    }
  
  //
  //	PytZ2->Scale(1./scale);
  
  Float_t scale = PytZ2_Vis->Integral()/PytZ2->Integral();
  cout << "MC scale =" << scale << endl;
  
  cout << "Float_t Z2Weight[] = {" ;
  for (Int_t j = 1;j<=19; j++)
    { 
      Float_t   ra = scale*pois_theory->GetBinContent(j)/PytZ2->GetBinContent(j);
      cout <<  ra << ", " ;
    }
  cout << " 0 }; " << endl;
  return;
}
示例#14
0
void CheckEHF()
{

 
  TH1F * HDat;
  TH1F * HDatnoPUAft;
  TH1F * HDatnoPUBef;

  //  TFile *fzee = new TFile("ZDiffOutputfile_73Weight2010.root");
  TFile *fzee = new TFile("ZDiffOutputfile_Data2011_noPU.root");
  // TFile *fzee = new TFile("ZDiffOutputfile.root");
  HDat  =  (TH1F*)fzee->Get("NVTX1_minEHFZoom_DATA10");
  HDatnoPUAft  =  (TH1F*)fzee->Get("NVTX1noPUAft_minEHFZoom_DATA10");
  HDatnoPUBef  =  (TH1F*)fzee->Get("NVTX1noPUBef_minEHFZoom_DATA10");

  HDat->Scale(1./HDat->GetEntries());
  HDatnoPUAft->Add(HDatnoPUBef);
  HDatnoPUAft->Scale(1./HDatnoPUAft->GetEntries());
  HDatnoPUBef->Scale(1./HDatnoPUBef->GetEntries());
  HDatnoPUAft->SetMinimum(0.);
  NHSetMarker(HDatnoPUAft,2,20,0.8);
  NHSetLine(HDatnoPUAft,2,1,1.);
  HDatnoPUAft->Draw("E1");
  HDatnoPUAft->SetTitle("2011 Z->ee Data, minHF Energy");
  NSetTitle(HDatnoPUAft,"HF Energy [GeV]", "Fraction");


  NHSetMarker(HDatnoPUBef,6,20,0.8);
  NHSetLine(HDatnoPUBef,6,1,1.);
  // HDatnoPUBef->Draw("SAMEP");

  NHSetMarker(HDat,4,20,0.8);
  NHSetLine(HDat,1,1,1.);
  HDat->Draw("SAMEP");

  TLegend *legend = new TLegend(0.6,0.1,0.75,0.4);
  legend->SetTextFont(72);
  legend->SetTextSize(0.04);
  legend->SetBorderSize(0);

  legend->AddEntry(HDatnoPUBef,"No PU before or after","p");
  //  legend->AddEntry(HDatnoPUBef,"No PU before","p");
  // legend->AddEntry(HDatnoPUAft,"No PU after","p");
  legend->AddEntry(HDat,"PU before && after","p");
  legend->Draw();






  //  NHSetLine(HDatnoPUBef,3,2,1.);
  // HDatnoPUBef->Draw("SAME HIST");

}
示例#15
0
BackgroundLL(){
  gStyle->SetPadGridX(0);
  gStyle->SetPadGridY(0);
  gStyle->SetCanvasColor(0);
  gStyle->SetOptStat(0);
  c=new TCanvas("tmp","tmp",700,500);
  float fptmin[7]={4.0,5.0,6.0,7.0,8.0,9.0,10.0};
  float fptmax[7]={5.0,6.0,7.0,8.0,9.0,10.0,25.0};
  TH1F* h5=new TH1F("A_LL_back","#vec{p}+#vec{p}->#pi^{0}X, #sqrt{s}=200Gev, 1.0#leq#eta#leq2.0;pT[Gev/c];A_{LL}_back",22,1.0,12.0);
  TH1F* h6=new TH1F("A_LL","#vec{p}+#vec{p}->#pi^{0}X, #sqrt{s}=200Gev, 1.089#leq#eta#leq2.0,P=60%;[Gev/c];A_{LL}",22,1.0,12.0);
  TH1F* h7=new TH1F("A_LL","#vec{p}+#vec{p}->#pi^{0}X, #sqrt{s}=200Gev, 1.089#leq#eta#leq2.0,P=60%;[Gev/c];A_{LL}",22,1.0,12.0);
  TH1F* h8=new TH1F("A_LL","#vec{p}+#vec{p}->#pi^{0}X, #sqrt{s}=200Gev, 1.089#leq#eta#leq2.0,P=60%;[Gev/c];A_{LL}",22,1.0,12.0);
  const int nBins = 7;
  float bins[nBins+1] = {4,5,6,7,8,9,10,12};
  TH1F* h4 = new TH1F("A_LL_back","#vec{p}+#vec{p}->#pi^{0}X, #sqrt{s}=200Gev, 1.0#leq#eta#leq2.0;pT[Gev/c];A_{LL};",nBins,bins);
  h4->SetMarkerStyle(8);
#endif
  TH1F* hSys = new TH1F("A_LL_back","#vec{p}+#vec{p}->#pi^{0}X, #sqrt{s}=200Gev, 1.0#leq#eta#leq2.0;pT[Gev/c];A_{LL};",nBins,bins);
  TH1F* hB = new TH1F("A_LL_back","#vec{p}+#vec{p}->#pi^{0}X, #sqrt{s}=200Gev, 1.0#leq#eta#leq2.0;pT[Gev/c];A_{LL};",nBins,bins);
  float baseLine=-0.14;
  float sysErr[7] = {0.00239,0.00521,0.00485,0.00405,0.012,0.0108,0.0104};


  psquare=0.3;

  for(int i=0;i<7;i++){
    float bgll=0.0,bgll_error=0.0,bgll1=0.0,bgll1_error=0.0,bgll2=0.0,bgll2_error=0.0;
    Background(i, fptmin[i], fptmax[i]);
    int Nsame1=bg1[i][0]+bg1[i][3];
    int Nanti1=bg1[i][1]+bg1[i][2];
    int Nsame2=bg2[i][0]+bg2[i][3];
    int Nanti2=bg2[i][1]+bg2[i][2];
    //int Nsame=Nsame1+Nsame2;
    //int Nanti=Nanti1+Nanti2;
    bgll1=1.0/psquare*(Nsame1-Nanti1)/(Nsame1+Nanti1);
    bgll1_error=1.0/psquare*1.0/sqrt(Nsame1+Nanti1);
    bgll2=1.0/psquare*(Nsame2-Nanti2)/(Nsame2+Nanti2);
    bgll2_error=1.0/psquare*1.0/sqrt(Nsame2+Nanti2);
    bgll=0.5*(bgll1+bgll2);
    bgll_error=0.5*(bgll1_error+bgll2_error);
    //bgll_error=sqrt(1.0/(1.0/pow(bgll1_error,2.0)+1.0/pow(bgll2_error,2.0)));
    cout<<"bgll="<<bgll<<" error1="<<bgll1_error<<" error2="<<bgll2_error<<" error="<<bgll_error<<endl;
    h4->Fill(fptmin[i]+0.5,bgll);
    int nbin0=h4->FindBin(fptmin[i]+0.5);
    h4->SetBinError(nbin0,bgll_error);
    //cout<<"point1 error="<<e3[0]<<" all="<<a3[0]<<endl;
    hSys->SetBinContent(nbin0,baseLine + sysErr[i]);
    hB->SetBinContent(nbin0,baseLine);

  }

  //open theory curve
  ifstream unp("theorycurve/pion-unp-cteq6-rap1to2.dat");
  ifstream g0("theorycurve/pion-pol-g0-rap1to2.dat");
  ifstream plusg("theorycurve/pion-pol-max-rap1to2.dat");
  ifstream minusg("theorycurve/pion-pol-maxminus-rap1to2.dat");
  ifstream stdg("theorycurve/pion-pol-std-rap1to2.dat");
  double x1=0.0,x2=0.0,x3=0.0,x4=0.0,x5=0.0;
  double d1=0.0,d2=0.0,d3=0.0,d4=0.0,d5=0.0;
  double b1=0.0,b2=0.0,b3=0.0,b4=0.0,b5=0.0;
  double c1=0.0,c2=0.0,c3=0.0,c4=0.0,c5=0.0;
  double y1=0.0,y2=0.0,y3=0.0,y4=0.0,y5=0.0;
  int ccount=0;
  double theoryd[18],theoryb[18],theoryc[18],theoryg[18];;
  while(1){
    unp>>y1>>y2>>y3>>y4>>y5;
    g0>>x1>>x2>>x3>>x4>>x5;
    plusg>>d1>>d2>>d3>>d4>>d5;
    minusg>>b1>>b2>>b3>>b4>>b5;
    stdg>>c1>>c2>>c3>>c4>>c5;
    theoryd[ccount]=d5/y5;
    theoryb[ccount]=b5/y5;
    theoryc[ccount]=c5/y5;
    theoryg[ccount]=x5/y5;
    //cout<<"x3="<<d3<<" theoryd="<<theoryg[ccount]<<endl;
    h5->Fill(d3,theoryd[ccount]);
    h6->Fill(b3,theoryb[ccount]);
    h7->Fill(c3,theoryc[ccount]);
    h8->Fill(x3,theoryg[ccount]);
    ccount++;
    if(ccount>17) break;
  }
  h5->Fill(8.0,0.03);
  h5->SetAxisRange(0,25,"X");
  h5->Fill(9.0,0.0305);
  h5->Fill(10.0,0.031);
  h5->Fill(10.5,0.0312);
  h5->Fill(11.5,0.031);
  h6->Fill(8.0,-0.001);
  h6->Fill(9.0,-0.0035);
  h6->Fill(10.0,-0.0065);
  h6->Fill(10.5,-0.0075);
  h6->Fill(11.5,-0.01);
  h7->Fill(8.0,0.0072);
  h7->Fill(9.0,0.0079);
  h7->Fill(10.0,0.0087);
  h7->Fill(10.5,0.0091);
  h7->Fill(11.5,0.0099);
  h8->Fill(8.0,0.00152);
  h8->Fill(9.0,0.00183);
  h8->Fill(10.0,0.00204);
  h8->Fill(10.5,0.0022);
  h8->Fill(11.5,0.0026);
#if 1
  //A_LL plotting
  c->cd(1);
  h5->SetLineColor(kRed);
  h5->Draw("C");
  h5->SetMinimum(-0.15);
  h5->SetMaximum(0.15);
  hB->SetFillColor(11);
  hB->Draw("same");
  hSys->SetFillColor(10);
  hSys->Draw("same");
  h6->SetLineColor(kGreen);
  h6->Draw("Csame");
  h7->Draw("Csame");
  h8->SetLineColor(kBlue);
  h8->Draw("Csame");

  h4->Draw("E1same,p");

  TLegend* leg = new TLegend(0.15,0.6,0.4,0.8);
  leg->AddEntry(h5,"#Delta{G}=G","L");
  leg->AddEntry(h6,"#Delta{G}=-G","L");
  leg->AddEntry(h7,"#Delta{G}=std","L");
  leg->AddEntry(h8,"#Delta{G}=0","L");
  leg->SetHeader("Vogelsang Prediction(GRSV)");
  leg->SetBorderSize(0.0);
  leg->SetFillColor(0.0);
  leg->Draw();
  TLegend* leg2 = new TLegend(0.6,0.75,0.9,0.85);
  leg2->SetHeader("STAR 2006 Preliminary #pi^{0}");
  leg2->SetBorderSize(0.0);
  leg2->SetFillColor(0.0);
  leg2->Draw();

#endif
  c->Print("tmp.gif");
}
void calculateEfficiencyFromNTUPLE_withGenWeights_v4(){

  if (variable_for_which_plot_eff == "etaSC") 
    doBarrel = true; // correct etaMode for eta variable
  
  TFile fi("/nas2/cmsdas/2016/SHORT_EXERCISES/ElectronsAndPhotons/samples/DY_Run2Asympt25ns_miniAOD_sept21_flat_ntuple_withWeights.root");   
  gDirectory->ls();
  TTree *tr          = (TTree*)gDirectory->Get("electronTree");

  TFile fiBG("/nas2/cmsdas/2016/SHORT_EXERCISES/ElectronsAndPhotons/samples/TT_Run2Asympt25ns_miniAOD_sept21_flat_ntuple_withWeights.root");   
  gDirectory->ls();
  TTree *trBG          = (TTree*)fiBG.Get("electronTree");
 

  float binLimitLow = 20;
  float binLimitUpper = 170;

  if(variable_for_which_plot_eff == "pt") {
    std::cout<<"\nVarible is  Pt, all is fine!" << std::endl;
  }
  else if(variable_for_which_plot_eff == "etaSC") {
    binLimitLow = -2.5;
    binLimitUpper = 2.5;
  }
  else if (variable_for_which_plot_eff == "nPV") {
    binLimitLow = 0;
    binLimitUpper = 50;
  } 
  else {
    std::cout<<"\n No no, can't happen!"<<"\nVarible is  "<<variable_for_which_plot_eff.Data() << std::endl;
  }
  

  TH1F *histVeto;
  TH1F *histVetoTot;
 
  TH1F *bg_histVeto;
  TH1F *bg_histVetoTot;


  if (variable_for_which_plot_eff != "nPV") {

    histVeto=new TH1F("histVeto","",nBins,binLimitLow, binLimitUpper);
    bg_histVeto=new TH1F("bg_histVeto","",nBins,binLimitLow, binLimitUpper);

    histVetoTot=new TH1F("histVetoTot","",nBins,binLimitLow, binLimitUpper);
    bg_histVetoTot=new TH1F("bg_histVetoTot","",nBins,binLimitLow, binLimitUpper);

    
  }
  else {
    nBins =24;
    histVeto=new TH1F("histVeto","",nBins,binLimits);
    bg_histVeto=new TH1F("bg_histVeto","",nBins,binLimits);
     
    histVetoTot=new TH1F("histVetoTot","",nBins,binLimits);
    bg_histVetoTot=new TH1F("bg_histVetoTot","",nBins,binLimits);
    
  }
  
  TCanvas *c = new TCanvas ("c", "c", 600, 600);
  c->SetFillColor(kWhite);
  gPad->SetLeftMargin(0.12);
  gPad->SetBottomMargin(0.11);

  TLatex Tl05;
  Tl05.SetTextAlign(23);
  Tl05.SetTextSize(0.04);
 

  const TString *pToCutsFile = nullptr;
  const TString *pToCutsFile_EtaEndcap = nullptr;
  if (doBarrel ) {
    pToCutsFile = cutFileNameBarrel;
    pToCutsFile_EtaEndcap = cutFileNameEndcap;
  }
  else {
    pToCutsFile = cutFileNameEndcap;
    pToCutsFile_EtaEndcap = cutFileNameEndcap;  //is not used here, just for aestetics purpose
  }


  if ( (variable_for_which_plot_eff == "pt" || variable_for_which_plot_eff == "nPV" ) && (doBarrel ==true) ){
    //      if (Pt <20 || Pt >200 || abs(EtaSC) > 1.566 ) continue; 
    std::cout<<"\nI'm here 3 "<<std::endl;
    // signal
    // pt/nPV barrel
    useHistograms( histVeto,    pToCutsFile, tr, false, ptOrPVBarrel, false,  pToCutsFile_EtaEndcap);  
    useHistograms( histVetoTot, pToCutsFile, tr, true, ptOrPVBarrel, false,  pToCutsFile_EtaEndcap);

    std::cout<<"\nI'm here 4 "<<std::endl;
    // BG
    // pt/nPV barrel
    useHistograms( bg_histVeto,    pToCutsFile, trBG, false, ptOrPVBarrel, true,  pToCutsFile_EtaEndcap); 
    useHistograms( bg_histVetoTot, pToCutsFile, trBG, true, ptOrPVBarrel, true,  pToCutsFile_EtaEndcap);  


  }
  else if ( (variable_for_which_plot_eff == "pt" || variable_for_which_plot_eff == "nPV" ) && doBarrel ==false){

    // signal
    // pt/nPV endcap
    useHistograms( histVeto,     pToCutsFile, tr, false, ptOrPVEndcap, false,  pToCutsFile_EtaEndcap); 
    useHistograms( histVetoTot,  pToCutsFile, tr, true, ptOrPVEndcap, false,  pToCutsFile_EtaEndcap); 


    // BG
    // pt/nPV endcap
    useHistograms( bg_histVeto,    pToCutsFile, trBG, false, ptOrPVEndcap, true,  pToCutsFile_EtaEndcap);  
    useHistograms( bg_histVetoTot, pToCutsFile, trBG, true, ptOrPVEndcap, true,  pToCutsFile_EtaEndcap);

    
  }
  else if (variable_for_which_plot_eff == "etaSC"){

    // signal
    // etaFullRange
    useHistograms( histVeto,     pToCutsFile, tr, false, etaFullRange, false, pToCutsFile_EtaEndcap); 
    useHistograms( histVetoTot,  pToCutsFile, tr, true, etaFullRange, false, pToCutsFile_EtaEndcap);  

    // BG
    // etaFullRange
    useHistograms( bg_histVeto,    pToCutsFile, trBG, false, etaFullRange, true, pToCutsFile_EtaEndcap);
    useHistograms( bg_histVetoTot, pToCutsFile, trBG, true, etaFullRange, true, pToCutsFile_EtaEndcap); 
    
  }
  else {
    std::cout<<"\nCan't happen! \nVariable is  "<<variable_for_which_plot_eff<<"  and eta is "<< (doBarrel?"barrel":"endcap")<<std::endl;
  }

  std::cout<<"\nI'm here 6 "<<std::endl;
 
  
  TH1F *effV = (TH1F*)histVeto->Clone("effV");
  TH1F *effV_bg = (TH1F*)bg_histVeto->Clone("effV_bg");

  std::cout<<"\nI'm here 7 "<<std::endl;
  
  calculateEffAndErrors(histVeto, histVetoTot, effV);
  calculateEffAndErrors(bg_histVeto, bg_histVetoTot, effV_bg);


  std::cout<<"\nI'm here 8 "<<std::endl;
  //  Usage :
  //  histogram, color_number, variable
  //
  setHistCosmetics(effV,4, variable_for_which_plot_eff);
  setHistCosmetics(effV_bg,38, variable_for_which_plot_eff);
  

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

  //if (variable_for_which_plot_eff == "etaSC" || variable_for_which_plot_eff == "nPV")   

  effV->GetYaxis()->SetRangeUser(0.,1.);
  effV->Draw("L");
  effV_bg->Draw("Lsame");
  effV->SetLineWidth(3);
  effV_bg->SetLineWidth(3);

  TLegend *leg = new TLegend(0.35, 0.52, 0.75, 0.65);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->AddEntry(effV, "WP Veto", "lf"); 
  leg->AddEntry((TObject*)0, "", "");
  leg->AddEntry(effV_bg, "BG WP Veto", "lf"); 
  leg->SetTextSize(0.03);
  leg->Draw("same");


  if (variable_for_which_plot_eff == "pt" ){
    if (doBarrel)
      Tl05.DrawLatex(40,1.1,"barrel electrons");
    else
      Tl05.DrawLatex(40,1.1,"endcap electrons");     
  }
  else if ( variable_for_which_plot_eff == "nPV" ){
    if (doBarrel)
      Tl05.DrawLatex(30,1.05,"barrel electrons");
    else
      Tl05.DrawLatex(30,1.05,"endcap electrons");     
  }


  c->Modified();
  c->Update();
  c->SaveAs( fileOut + ".png");
  
  effV->SetDirectory(0);
  effV_bg->SetDirectory(0);
  
  DYfile->cd();
  effV->Write("WP_Veto");
  effV_bg->Write("BG_WP_Veto");

  c->Write();
  DYfile->Close();
}
示例#17
0
void optimization0803(){

  

  TH1F * th1 =new TH1F("HMass","HMass",600,0,600); 
  TH1F * th2 =new TH1F("Pt of good","Pt of good",2000,0,2000); 
  TH1F * th3 =new TH1F("Pt of bad","P of bad",2000,0,2000);
  TH1F * thr =new TH1F("Dr of good","deltaR of good",50,0,3);
  TH1F * thr2 =new TH1F("Dr of bad","deltaR of bad",50,0,3);

  //DY bkg
  // TString endfix ="DYBkg";
  // double scaleF=0;
  // double xsecF=2008.4;
  // for(int w=1;w<363;w++){
  //   f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/crab_DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_ForEIKO/150729_202330/0000/NCUGlobalTuples_%d.root",w));
  //   if (!f || !f->IsOpen())continue;
  //   TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8/crab_DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_ForEIKO/150729_202330/0000/NCUGlobalTuples_%d.root:/tree",w));
  //   dir->GetObject("treeMaker",tree);


  //BulkGravitonZlepZqq  noCleaning_BulkGravToZZToZlepZhad_narrow_M-1000_13TeV-madgraph.root
   string  masspoint[13]={"600","800","1000","1200","1400","1600","1800","2000","2500","3000","3500","4000","4500"};
   double xsecFB[13]={0.046310769831789535,0.010953371285280107,0.0033153186581553304,0.0011796819730577413,0.0004688386674106958,0.00025472097,0.00007503744,0.00004542880185027153,8.614571731526816e-6,1.9201182127764607e-6,4.25018556e-7,9.40119436e-8,2.08241719e-8};
  double xsecFB2[13]={0.184219,0.142802,0.125936,0.117445,0.112554,0.109472,0.101401,0.10594,0.103732,0.102549,0.101841,0.101384,0.100927};
     for (int massP=0;massP<13;massP++){
       TString endfix =Form("BulkGravitonZlepZqq-%s",masspoint[massP].data());
       double scaleF=0;
       double xsecF=xsecFB[massP]*xsecFB2[massP]*0.047063412;
      for(int w=1;w<2;w++){
  	 f = TFile::Open(Form("/data2/syu/13TeV/BulkGravitonZlepZqq/noCleaning_BulkGravToZZToZlepZhad_narrow_M-%s_13TeV-madgraph.root",masspoint[massP].data()));
  	 if (!f || !f->IsOpen())continue;
  	 TDirectory * dir = (TDirectory*)f->Get(Form("/data2/syu/13TeV/BulkGravitonZlepZqq/noCleaning_BulkGravToZZToZlepZhad_narrow_M-%s_13TeV-madgraph.root:/tree",masspoint[massP].data()));
   	 dir->GetObject("treeMaker",tree);


  //Signal

   // string  masspoint[13]={"600","800","1000","1200","1400","1600","1800","2000","2500","3000","3500","4000","4500"};
   // string  crabInf[13]={"150729_212416","150729_212459","150729_211555","150729_211640","150729_211727","150729_211727","150729_211855","150729_211940","150729_212023","150729_212110","150729_212159","150729_212245","150729_212331"};
   // for (int massP=0;massP<13;massP++){
   // TString endfix =Form("signal-%s",,masspoint[massP].data());
   // for(int w=1;w<3;w++){
   //   f = TFile::Open(Form("/data7/khurana/NCUGlobalTuples/SPRING15/ZPrimeSignal/ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph/crab_ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph/%s/0000/NCUGlobalTuples_%d.root",masspoint[massP].data(),masspoint[massP].data(),crabInf[massP].data(),w));
   // if (!f || !f->IsOpen())continue;
   // TDirectory * dir = (TDirectory*)f->Get(Form("/data7/khurana/NCUGlobalTuples/SPRING15/ZPrimeSignal/ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph/crab_ZprimeToZhToZlephbb_narrow_M-%s_13TeV-madgraph/%s/0000/NCUGlobalTuples_%d.root:/tree",masspoint[massP].data(),masspoint[massP].data(),crabInf[massP].data(),w));
   // dir->GetObject("treeMaker",tree);

  cout<<w<<endl;

  TreeReader data(tree);
  //data.Print();
  Long64_t nLepton[3]={0};
  Long64_t nTotal=0;
  Long64_t nPass[20]={0};
  ofstream fout;
  fout.open("ele_Eiko.txt");

  //Event loop
  for(Long64_t jEntry=0; jEntry<data.GetEntriesFast() ;jEntry++){

    if (jEntry % 50000 == 0)
      fprintf(stderr, "Processing event %lli of %lli\n", jEntry + 1, data.GetEntriesFast());

    data.GetEntry(jEntry);
    nTotal ++;
    
    Int_t nGenPar        = data.GetInt("nGenPar");
    Int_t* genParId      = data.GetPtrInt("genParId");
    Int_t* genParSt      = data.GetPtrInt("genParSt");
    Int_t* genMomParId   = data.GetPtrInt("genMomParId");
    Int_t* genDa1      = data.GetPtrInt("genDa1");
    Int_t* genDa2      = data.GetPtrInt("genDa2");
    TClonesArray* genParP4 = (TClonesArray*) data.GetPtrTObject("genParP4");

    bool hasElectron=false;

    for(int ig=0; ig < nGenPar; ig++){

        int pid = abs(genParId[ig]);
        if(pid!=11)continue;
        int momId = abs(genMomParId[ig]);
        if(
            momId!=23 &&
            momId!=9000001 &&
            momId!=pid)
        continue;
        hasElectron=true;
        if(hasElectron)break;

    }

    if(!hasElectron)continue;
    nPass[0]++;

    // bool hasHadron=false;

    // for(int ig=0; ig < nGenPar; ig++){

    //     int pid = abs(genParId[ig]);
    //     //if(pid!=11)continue;
    //     int momId = abs(genMomParId[ig]);
    //     if(
    //         momId!=25 &&
    //         momId!=9000001 &&
    //         momId!=pid)
    //     continue;
    //     hasHadron=true;
    //     if(hasHadron)break;


    // }
    


    // if(!hasHadron)continue;
    // nPass[1]++;
  
    TLorentzVector* thisB ,* thatB;
    bool isThisB=0,isThatB=0;
    vector<int> thisBArray;

    for(int ig=0; ig < nGenPar; ig++){
      if(isThisB && isThatB)continue;
        int pid = abs(genParId[ig]);
        int momId = abs(genMomParId[ig]);
        if(
            momId!=25 &&
            momId!=9000001 &&
            momId!=pid)
        continue;
	if (pid==5)thisBArray.push_back(ig);
        if (pid==5 && !isThisB){
	  thisB= (TLorentzVector*)genParP4->At(ig);
	  isThisB=1;
	  continue;
	}
	if(pid==5 && isThisB && !isThatB){
	  thatB= (TLorentzVector*)genParP4->At(ig);
          isThatB=1;
	}
	

    }
    //if (thisBArray.size()!=2)cout<<"thisBArray.size()="<<thisBArray.size()<<" , entry="<<jEntry<<endl;

     
    std::string* trigName = data.GetPtrString("hlt_trigName");
    vector<bool> &trigResult = *((vector<bool>*) data.GetPtr("hlt_trigResult"));
    const Int_t nsize = data.GetPtrStringSize();

    bool passTrigger=false;
    for(int it=0; it< nsize; it++)
      {
 	std::string thisTrig= trigName[it];
 	bool results = trigResult[it];

	// std::cout << thisTrig << " : " << results << std::endl;
	
 	if( (thisTrig.find("HLT_Ele105")!= std::string::npos && results==1)
	    ||
	    (thisTrig.find("HLT_Mu45")!= std::string::npos && results==1)
	    )
 	  {
 	    passTrigger=true;
 	    break;
 	  }


      }


    if(!passTrigger)continue;
    nPass[2]++;

    

    Int_t nVtx        = data.GetInt("nVtx");
    if(nVtx<1)continue;
    nPass[3]++;

    Int_t nEle         = data.GetInt("nEle");
    Int_t run          = data.GetInt("runId");
    Int_t lumi         = data.GetInt("lumiSection");
    Int_t event        = data.GetInt("eventId");
    vector<bool> &passHEEPID = *((vector<bool>*) data.GetPtr("eleIsPassHEEPNoIso"));
    TClonesArray* eleP4 = (TClonesArray*) data.GetPtrTObject("eleP4");
    Float_t* eleSCEta         = data.GetPtrFloat("eleScEta");
    Float_t* eleMiniIso       = data.GetPtrFloat("eleMiniIso");
    Int_t*   eleCharge        = data.GetPtrInt("eleCharge");

    bool findEPair=false;
    TLorentzVector l4_Z(0,0,0,0);
    std::vector<int> myElectrons;

    // select_electrons(data, myElectrons);

    // select good electrons

    for(int ie=0; ie< nEle; ie++)
      {

    	TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie);

    	if(fabs(thisEle->Eta())>2.5)continue;

    	if(! (fabs(eleSCEta[ie])<1.442 || fabs(eleSCEta[ie])>1.566))continue;
    	
    	if(thisEle->Pt() < 115)continue;

    	if(!passHEEPID[ie])continue;
    	
    	if(eleMiniIso[ie]>0.1)continue;

    	myElectrons.push_back(ie);
      }

    TLorentzVector * checkThisEle, * checkThatEle;

    for(unsigned int i=0; i< myElectrons.size(); i++)
      {
	int ie = myElectrons[i];
	TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(ie);

	for(unsigned int j=0; j< i; j++)
	  {
	    int je= myElectrons[j];

	    if(eleCharge[ie]*eleCharge[je]>0)continue;

	    TLorentzVector* thatEle = (TLorentzVector*)eleP4->At(je);

	    Float_t mll  = (*thisEle+*thatEle).M();
	    Float_t ptll = (*thisEle+*thatEle).Pt();
	    

	    if(mll<70 || mll>110)continue;
	    if(ptll<200)continue;

	    if(!findEPair){
	      l4_Z=(*thisEle+*thatEle);
	      checkThisEle = thisEle;
              checkThatEle = thatEle;
	    }
	    findEPair=true;
	  }	
      }

    if(!findEPair)
      continue;
    nPass[4]++;

    //cout<<"a"<<jEntry<<endl;

    Int_t nJet         = data.GetInt("FATnJet");
    TClonesArray* jetP4 = (TClonesArray*) data.GetPtrTObject("FATjetP4");
    Float_t*  jetSDmass = data.GetPtrFloat("FATjetSDmass");

    TLorentzVector l4_leadingJet(0,0,0,0);
    bool findAJet=false;
    bool goodJet=0;



    for(int ij=0; ij<nJet; ij++)
      {
	
	TLorentzVector* thisJet = (TLorentzVector*)jetP4->At(ij);

	//if(jetSDmass[ij]<50 || jetSDmass[ij]>110)continue;
        if (thisJet->DeltaR(*checkThisEle)<0.8)continue;
        if (thisJet->DeltaR(*checkThatEle)<0.8)continue;
        if (thisJet->Pt()<20 || thisJet->Eta()>2.4)continue;
        bool checkMyEle=0;
        for (unsigned int k=0;k<myElectrons.size();k++){
          TLorentzVector* thisEle = (TLorentzVector*)eleP4->At(myElectrons[k]);
	  if (thisJet->DeltaR(*thisEle)<0.8)checkMyEle=1;
	}
	if (checkMyEle)continue;
        if (jetSDmass[ij]<20||jetSDmass[ij]>220)continue;
	if(!findAJet){
	  l4_leadingJet = *thisJet;
          th1->Fill(jetSDmass[ij]);
          if(jetSDmass[ij]<20){
	    th3->Fill(thisJet->Pt());
	    //thr2->Fill(thisB->DeltaR(*thatB));
	  }
	  else {
	    //thr->Fill(thisB->DeltaR(*thatB));
	    th2->Fill(thisJet->Pt());
	  }
	  //if (thisJet->DeltaR(*thisB)<0.8)goodJet=1;
          //else if (thisJet->DeltaR(*thatB)<0.8)goodJet=1;
	}
	//cout<<"b"<<endl;
	findAJet=true;
      }
    
    
    if(!findAJet)
      continue;
    nPass[5]++;
    //if(!goodJet)l4_leadingJet.Print();



    Float_t MGrav = (l4_leadingJet + l4_Z).M();
    if(MGrav<400)continue;
    nPass[6]++;

    fout << run << " " << lumi << " " << event << endl;
    

  } // end of loop over entries

  fout.close();
  std::cout << "nTotal    = " << nTotal << std::endl;
  for(int i=0; i<3; i++)
    std::cout << "nLepton[" << i << "]    = " << nLepton[i] << std::endl;
  for(int i=0;i<20;i++)
    if(nPass[i]>0)
      std::cout << "nPass[" << i << "]= " << nPass[i] << std::endl;
  //th1->Draw();
  scaleF+=nPass[0];

  }
  TFile* outFile = new TFile(Form("root_files/%s.root",endfix.Data()),"recreate");       
  
  th1->Sumw2();
  th1->Scale(5000*xsecF/scaleF);
  th1->Write();
  th2->Write();
  th3->Write();
  thr->Write();
  thr2->Write();
  outFile->Close();

  int width [nWidth]={30,35,50,45,50};
  int bmin[nBmin]={91,93,95,97,99,101,103,105,107,109};
  double eff[nWidth][nBmin];
  for(int i=0;i<nWidth;i++){
    for(int j=0;j<nBmin;j++){
      //eff[i][j]=getEff(th1,bmin[j],bmin[j]+width[i]);
      //cout<<"range={"<<bmin[j]<<","<<bmin[j]+width[i]<<"} and efficiency="<<eff[i][j]<<endl;
    }
  }

  
  }

    }//sig mass point
示例#18
0
void Test::Loop()
{
   if (fChain == 0) return;
TFile *f = new TFile("test.root","RECREATE");
   Long64_t nentries = fChain->GetEntries();
TH1F *HitEnergy  = new TH1F("HitEnergy","Energy of Reconstructed Hit", 200, 0, 10);
TH1F *HitTime  = new TH1F("HitTime","Timing", 300, -60, 60);
TH1F *HitEt = new TH1F("HitEt","Et of Reconstructed Hit", 200, 0, 10);
TH1F *HitIfkWeird = new TH1F("HitIfkWeird","kWeird of Reconstructed Hit", 200, -10, 10);
TH1F *HitSwissCross = new TH1F("HitSwissCross","swissCross of Reconstructed Hit", 200, 0, 10);
TH2F *HitSwissCross_HitTime = new TH2F("HitSwissCross_HitTime","Swiss-cross vs. time of MultiFit", 200, 0.2, 2, 100, -60, 60);
TH1F *HitIfkOOT = new TH1F("HitIfkOOT","kOOT  of Reconstructed Hit", 200, -10, 10);
TH1F *HitIfkDiWeird = new TH1F("HitIfkDiWeird","kDiWeird of Reconstructed Hit", 200, -10, 10);
TH2F *HitIfkDiWeird_HitIfkWeird = new TH2F("HitIfkDiWeird_HitIfkWeird","kDiWeird+KWeird",200, 0.2, 1.2, 200, -60, 60);
//TH2F *HitIfkDiWeird_HitIfkWeird_HitIfkOOT = new TH2F("HitIfkDiWeird_HitIfkWeird_HitIfkOOT","kDiWeird+KWeird+ifkOOT",200, 0.2, 1.2, 200, -60, 60);
//TH1F *HitIfkDiWeird_HitIfkWeird_HitIfkOOT = new TH1F("HitIfkDiWeird_HitIfkWeird_HitIfkOOT","kDiWeird+KWeird+kOutOfTime",200, 0.2, 2);
   Long64_t nbytes = 0, nb = 0;
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
      // if (Cut(ientry) < 0) continue;
unsigned int temp;
temp = Rechit_energy->size();
printf("Total number of rec hits in this event %d\n", temp);
for(unsigned int ihit=0; ihit !=Rechit_energy->size(); ++ihit){
if( Rechit_energy->at(ihit) > 4){
printf("energy & time of rec hit number %d\t is %f\t%f\n", ihit, Rechit_energy->at(ihit), Rechit_time->at(ihit));
HitEnergy->Fill(Rechit_energy->at(ihit));
HitTime->Fill(Rechit_time->at(ihit));
HitEt->Fill(Rechit_et->at(ihit));
HitSwissCross->Fill(Rechit_swissCross->at(ihit));
HitIfkWeird->Fill(Rechit_ifkWeird->at(ihit));
HitSwissCross_HitTime->Fill(Rechit_swissCross->at(ihit), Rechit_time->at(ihit));
HitSwissCross_HitTime->GetXaxis()->SetTitle("Swiss-Cross");
HitSwissCross_HitTime->GetXaxis()->CenterTitle(1);
HitSwissCross_HitTime->GetYaxis()->SetTitle("RecHit Timing[ns]");
HitSwissCross_HitTime->GetYaxis()->CenterTitle(1);
HitIfkOOT->Fill(Rechit_ifkOOT->at(ihit));
HitIfkDiWeird->Fill(Rechit_ifkDiWeird->at(ihit));
if(Rechit_swissCross->at(ihit) > 0.95) {
HitIfkDiWeird_HitIfkWeird->Fill(Rechit_swissCross->at(ihit), Rechit_time->at(ihit));
HitIfkDiWeird_HitIfkWeird->GetXaxis()->SetTitle("Swiss-Cross");
HitIfkDiWeird_HitIfkWeird->GetXaxis()->CenterTitle(1);
HitIfkDiWeird_HitIfkWeird->GetYaxis()->SetTitle("RecHit Timing[ns]");
HitIfkDiWeird_HitIfkWeird->GetYaxis()->CenterTitle(1);


/*HitIfkDiWeird_HitIfkWeird_HitIfkOOT->Fill(Rechit_swissCross->at(ihit), Rechit_time->at(ihit));
HitIfkDiWeird_HitIfkWeird_HitIfkOOT->GetXaxis()->SetTitle("Swiss-Cross");
HitIfkDiWeird_HitIfkWeird_HitIfkOOT->GetXaxis()->CenterTitle(1);
HitIfkDiWeird_HitIfkWeird_HitIfkOOT->GetYaxis()->SetTitle("RecHit Timing[ns]");
HitIfkDiWeird_HitIfkWeird_HitIfkOOT->GetYaxis()->CenterTitle(1);*/

//HitIfkDiWeird_HitIfkWeird_HitIfkOOT->Fill(Rechit_ifkDiWeird->at(ihit))+(Rechit_ifkWeird->at(ihit))+(Rechit_ifkOOT->at(ihit));

//cout << "hit " << ihit << "\tEnergy " << Rechit_energy->at(ihit) << endl;
}
}
}
cout << "****************************" << endl;

   }
f->Write();
f->Close();
}
示例#19
0
void fragmentYieldsPlot() {
   gStyle->SetOptStat(0000000000); //remove the for this graphs totally redundant statbox
   int ZNumGiven;
   cout << "Enter fragment Z-number (eg. 1): ";
   cin >> ZNumGiven;

   TCanvas *c1 = new TCanvas("fragmentYieldsPlot", "Total yield of fragments zero to ten degrees as function of depth");
   
   TString fragmentNameChoices[6] = {"H","He","Li","Be","B","C"};
   
   TString fragmentName = fragmentNameChoices[ZNumGiven-1];  
   
   std::cout << fragmentName << endl;
   
   TH1F* dummyHisto = new TH1F("dummyHisto", fragmentName + " yields 0-10 degrees" ,100, 0.0,40); //Dummyhisto fix for missing TNtuple methods.
   dummyHisto->SetXTitle("Depth (cm)");
   dummyHisto->SetYTitle("N/N0");

   ifstream in;
   TString experimentalDataPath = "experimentalData/iaeaBenchmark/yields/TDK" + fragmentName + ".dat";
   
   ifstream in;

   //Pull in ascii/exfor-style data
   in.open(experimentalDataPath);

   Float_t f1,f2;
   Int_t nlines = 0;
   TFile *f = new TFile("fragmentAngularDistribution.root","RECREATE");
   TNtuple *ntuple = new TNtuple("ntuple","Data from ascii file","x:y");
	  
   Char_t DATAFLAG[4];
   Int_t NDATA;
   Char_t n1[15], n2[15];
   in >> DATAFLAG >> NDATA ; // Read EXFOR line: 'DATA 6'
   in >> n1 >> n2; // Read  column titles: 'Energy He B [...]'

   cout <<n1<<"   "<<n2<<"\n";
   while (1) {
      in >> f1 >> f2;
      if (!in.good()) break;
      if (nlines < 500 ) printf("%f %f\n",f1,f2);
      ntuple->Fill(f1,f2);
      nlines++;
   }
   std::cout << "Imported " << nlines << " lines from data-file" << endl;




   TNtuple *simData = new TNtuple("ntuple","Data from ascii file","depth:H:He:Li:Be:B:C");
   
//   gROOT->SetStyle("clearRetro");
 //this will be used as base for pulling the experimental data
   TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
   dir.ReplaceAll("fragmentAngularDistribution.C","");
   dir.ReplaceAll("/./","/");
   ifstream in;
   simData->Fill(0.0,0.0,0.0,0.0,0.0,0.0,1.0);
for(int j = 1; j <= 40;j=j=j+1){
   TString pDepth, fragment, Znum, normToOneAtZeroAngle;
   pDepth = Form("%i",j);
/*
   cout << "Enter phantom depth (eg. 27.9, see experimentalData directory for choices): ";
   cin >> pDepth;
*/
   TString simulationDataPath = "IAEA_" + pDepth + ".root";

   //Let's pull in the simulation-data
   //TFile *MCData = TFile::Open("IAEA_" + pDepth + ".root");
   TFile *MCData = TFile::Open(simulationDataPath);
   TNtuple *fragments = (TNtuple*) MCData->Get("fragmentNtuple");

   //Block bellow pulls out the simulation's metadata from the metadata ntuple.
   TNtuple *metadata = (TNtuple*) MCData->Get("metaData");
   Float_t events, detectorDistance,waterThickness,beamEnergy,energyError,phantomCenterDistance;
   metadata->SetBranchAddress("events",&events);
   metadata->SetBranchAddress("waterThickness",&waterThickness);
   metadata->SetBranchAddress("detectorDistance",&detectorDistance);
   metadata->SetBranchAddress("beamEnergy",&beamEnergy);
   metadata->SetBranchAddress("energyError",&energyError);
   metadata->SetBranchAddress("phantomCenterDistance",&phantomCenterDistance);
   metadata->GetEntry(0); //there is just one row to consider.
	//ALL UNITS ARE cm!
	Double_t scatteringDistance = detectorDistance - phantomCenterDistance; //temporarily hard-coded, should be distance from target-center to detector

	Double_t degrees = 10.0;
	Double_t r, rMin, rMax, graphMaximum = 0.0;
	Double_t norming = events*.999;
	TString rMinString;
	TString rMaxString;

	rMinString = "0.00";
	rMaxString = Form("%f", scatteringDistance*TMath::ATan(degrees*TMath::DegToRad()));

		Double_t H = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",1) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t He = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",2) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t Li = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",3) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t Be = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",4) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t B = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",5) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		Double_t C = ((Double_t*) fragments->GetEntries("(Z == " + TString::Format("%i",6) + "  && sqrt(posY^2 + posZ^2) < " + rMaxString + "&& sqrt(posY*posY + posZ*posZ) > " + rMinString + ")")) / norming;
		simData->Fill(waterThickness,H,He,Li,Be,B,C);

	}
	simData->Scan();
	simData->SetMarkerStyle(2); //filled dot
	simData->SetMarkerColor(kBlue);
	graphMaximum = TMath::Max(graphMaximum, simData->GetMaximum(fragmentName));
	graphMaximum = TMath::Max(graphMaximum, ntuple->GetMaximum("y"));
	dummyHisto->SetMaximum(graphMaximum + .05*graphMaximum);
	dummyHisto->Draw();
	
	simData->Draw(fragmentName + ":depth","","p,same");

	ntuple->SetMarkerStyle(22); //triangle
    ntuple->SetMarkerColor(kRed);
	ntuple->Draw("y:x","","p,same");
	c1->SaveAs("fragmentYieldsFor" + fragmentName + ".png");
}
int main( int argc, const char* argv[] ){

  // List of arguments:
  // 0: The executable itself
  // 1: The number of times JetMET is smeared (not smeared if equal to 1)
  // 2: The scale and type of JES shift (if fabs(x) < 0.5, shift by eta, else absolute

// fixme: Depracated
   float JES_JetMET = 1.0;

  string xmlFileName = string ("./MyMassAnalysis.xml");

  for (int i=1;i<argc;++i) {
    if (strncmp(argv[i],"-c",2)==0) xmlFileName = string(argv[i+1]);
    if (strncmp(argv[i],"-h",2)==0) {
      cout << " -c xm_config_file\n";
      exit(1);
    }
  }

  cout<<"#########################"<<endl;
  cout<<"Beginning of the program"<<endl;
  cout<<"#########################"<<endl;

  //////////////////////
  //Global variables
  //////////////////////

  // GEN
  TH1F * histoGenTopRapidity1 = new TH1F("GenTopRapidity1", "GenTopRapidity1", 100, -5, 5);
  TH1F * histoGenTopRapidity2 = new TH1F("GenTopRapidity2", "GenTopRapidity2", 100, -5, 5);
  TH1F * histoGenTopMass1 = new TH1F("GenTopMass1", "GenTopMass1", 200, 0, 200);
  TH1F * histoGenTopMass2 = new TH1F("GenTopMass2", "GenTopMass2", 200, 0, 200);
  TH2F * histoGenTopMass1VsTopMass2 = new TH2F("GenTopMass1VsTopMass2", "GenTopMass1VsTopMass2", 200, 0, 200, 200, 0, 200);
  TH1F * histoGenDelta_y = new TH1F("GenDelta_y", "GenDelta_y", 400, -2, 2);
  TH1F * histoGenTTRapidity = new TH1F("GenTTRapidity", "GenTTRapidity", 500, -2.5, 2.5);
  TH1F * histoGenTTPt = new TH1F("GenTTPt", "GenTTPt", 250, 0, 250);
  TH1F * histoGenTTMass = new TH1F("GenTTMass", "GenTTMass", 100, 0, 1000);

  TH2F * histoGenDelta_yVsTTRapidity = new TH2F("GenDelta_yVsTTRapidity", "GenDelta_yVsTTRapidity", 10, -2, 2, 5, -2.5, 2.5);
  TH2F * histoGenDelta_yVsTTPt = new TH2F("GenDelta_yVsTTPt", "GenDelta_yVsTTPt", 10, -2, 2, 5, 0, 250);
  TH2F * histoGenDelta_yVsTTMass = new TH2F("GenDelta_yVsTTMass", "GenDelta_yVsTTMass", 10, -2, 2, 5, 0, 1000);
  TH1F * histoGenN_plusTTRapidity = new TH1F("GenN_plusTTRapidity", "GenN_plusTTRapidity", 20, -2.5, 2.5);
  histoGenN_plusTTRapidity->Sumw2();
  TH1F * histoGenN_plusTTPt = new TH1F("GenN_plusTTPt", "GenN_plusTTPt", 20, 0, 250);
  histoGenN_plusTTPt->Sumw2();
  TH1F * histoGenN_plusTTMass = new TH1F("GenN_plusTTMass", "GenN_plusTTMass", 20, 0, 1000);
  histoGenN_plusTTMass->Sumw2();
  TH1F * histoGenN_minusTTRapidity = new TH1F("GenN_minusTTRapidity", "GenN_minusTTRapidity", 20, -2.5, 2.5);
  histoGenN_minusTTRapidity->Sumw2();
  TH1F * histoGenN_minusTTPt = new TH1F("GenN_minusTTPt", "GenN_minusTTPt", 20, 0, 250);
  histoGenN_minusTTPt->Sumw2();
  TH1F * histoGenN_minusTTMass = new TH1F("GenN_minusTTMass", "GenN_minusTTMass", 20, 0, 1000);
  histoGenN_minusTTMass->Sumw2();
  TH1F * histoGenN_plusMinusN_minusTTRapidity = new TH1F("GenN_plusMinusN_minusTTRapidity", "GenN_plusMinusN_minusTTRapidity", 20, -2.5, 2.5);
  histoGenN_plusMinusN_minusTTRapidity->Sumw2();
  TH1F * histoGenN_plusPlusN_minusTTRapidity = new TH1F("GenN_plusPlusN_minusTTRapidity", "GenN_plusPlusN_minusTTRapidity", 20, -2.5, 2.5);
  histoGenN_plusPlusN_minusTTRapidity->Sumw2();
  TH1F * histoGenN_plusMinusN_minusTTPt = new TH1F("GenN_plusMinusN_minusTTPt", "GenN_plusMinusN_minusTTPt", 20, 0, 250);
  histoGenN_plusMinusN_minusTTPt->Sumw2();
  TH1F * histoGenN_plusPlusN_minusTTPt = new TH1F("GenN_plusPlusN_minusTTPt", "GenN_plusPlusN_minusTTPt", 20, 0, 250);
  histoGenN_plusPlusN_minusTTPt->Sumw2();
  TH1F * histoGenN_plusMinusN_minusTTMass = new TH1F("GenN_plusMinusN_minusTTMass", "GenN_plusMinusN_minusTTMass", 20, 0, 1000);
  histoGenN_plusMinusN_minusTTMass->Sumw2();
  TH1F * histoGenN_plusPlusN_minusTTMass = new TH1F("GenN_plusPlusN_minusTTMass", "GenN_plusPlusN_minusTTMass", 20, 0, 1000);
  histoGenN_plusPlusN_minusTTMass->Sumw2();
  TH1F * histoGenA_cTTRapidity = new TH1F("GenA_cTTRapidity", "GenA_cTTRapidity", 20, -2.5, 2.5);
  histoGenA_cTTRapidity->Sumw2();
  TH1F * histoGenA_cTTPt = new TH1F("GenA_cTTPt", "GenA_cTTPt", 20, 0, 250);
  histoGenA_cTTPt->Sumw2();
  TH1F * histoGenA_cTTMass = new TH1F("GenA_cTTMass", "GenA_cTTMass", 20, 0, 1000);
  histoGenA_cTTMass->Sumw2();
  // Fine binning
  TH2F * histoFineBinning_GenDelta_yVsTTRapidity = new TH2F("FineBinning_GenDelta_yVsTTRapidity", "FineBinning_GenDelta_yVsTTRapidity", 200, -2, 2, 500, -2.5, 2.5);
  TH2F * histoFineBinning_GenDelta_yVsTTPt = new TH2F("FineBinning_GenDelta_yVsTTPt", "FineBinning_GenDelta_yVsTTPt", 200, -2, 2, 250, 0, 250);
  TH2F * histoFineBinning_GenDelta_yVsTTMass = new TH2F("FineBinning_GenDelta_yVsTTMass", "FineBinning_GenDelta_yVsTTMass", 200, -2, 2, 100, 0, 1000);
  TH1F * histoFineBinning_GenN_plusTTRapidity = new TH1F("FineBinning_GenN_plusTTRapidity", "FineBinning_GenN_plusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenN_plusTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenN_plusTTPt = new TH1F("FineBinning_GenN_plusTTPt", "FineBinning_GenN_plusTTPt", 250, 0, 250);
  histoFineBinning_GenN_plusTTPt->Sumw2();
  TH1F * histoFineBinning_GenN_plusTTMass = new TH1F("FineBinning_GenN_plusTTMass", "FineBinning_GenN_plusTTMass", 100, 0, 1000);
  histoFineBinning_GenN_plusTTMass->Sumw2();
  TH1F * histoFineBinning_GenN_minusTTRapidity = new TH1F("FineBinning_GenN_minusTTRapidity", "FineBinning_GenN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenN_minusTTPt = new TH1F("FineBinning_GenN_minusTTPt", "FineBinning_GenN_minusTTPt", 250, 0, 250);
  histoFineBinning_GenN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_GenN_minusTTMass = new TH1F("FineBinning_GenN_minusTTMass", "FineBinning_GenN_minusTTMass", 100, 0, 1000);
  histoFineBinning_GenN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_GenN_plusMinusN_minusTTRapidity = new TH1F("FineBinning_GenN_plusMinusN_minusTTRapidity", "FineBinning_GenN_plusMinusN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenN_plusMinusN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenN_plusPlusN_minusTTRapidity = new TH1F("FineBinning_GenN_plusPlusN_minusTTRapidity", "FineBinning_GenN_plusPlusN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenN_plusPlusN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenN_plusMinusN_minusTTPt = new TH1F("FineBinning_GenN_plusMinusN_minusTTPt", "FineBinning_GenN_plusMinusN_minusTTPt", 250, 0, 250);
  histoFineBinning_GenN_plusMinusN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_GenN_plusPlusN_minusTTPt = new TH1F("FineBinning_GenN_plusPlusN_minusTTPt", "FineBinning_GenN_plusPlusN_minusTTPt", 250, 0, 250);
  histoFineBinning_GenN_plusPlusN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_GenN_plusMinusN_minusTTMass = new TH1F("FineBinning_GenN_plusMinusN_minusTTMass", "FineBinning_GenN_plusMinusN_minusTTMass", 100, 0, 1000);
  histoFineBinning_GenN_plusMinusN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_GenN_plusPlusN_minusTTMass = new TH1F("FineBinning_GenN_plusPlusN_minusTTMass", "FineBinning_GenN_plusPlusN_minusTTMass", 100, 0, 1000);
  histoFineBinning_GenN_plusPlusN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_GenA_cTTRapidity = new TH1F("FineBinning_GenA_cTTRapidity", "FineBinning_GenA_cTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_GenA_cTTRapidity->Sumw2();
  TH1F * histoFineBinning_GenA_cTTPt = new TH1F("FineBinning_GenA_cTTPt", "FineBinning_GenA_cTTPt", 250, 0, 250);
  histoFineBinning_GenA_cTTPt->Sumw2();
  TH1F * histoFineBinning_GenA_cTTMass = new TH1F("FineBinning_GenA_cTTMass", "FineBinning_GenA_cTTMass", 100, 0, 1000);
  histoFineBinning_GenA_cTTMass->Sumw2();


  // RECO
  TH1F * histoRecoTopRapidity1 = new TH1F("RecoTopRapidity1", "RecoTopRapidity1", 100, -5, 5);
  TH1F * histoRecoTopRapidity2 = new TH1F("RecoTopRapidity2", "RecoTopRapidity2", 100, -5, 5);
  TH1F * histoRecoLeptonRapidity1 = new TH1F("RecoLeptonRapidity1", "RecoLeptonRapidity1", 100, -5, 5);
  TH1F * histoRecoLeptonRapidity2 = new TH1F("RecoLeptonRapidity2", "RecoLeptonRapidity2", 100, -5, 5);
  TH1F * histoRecoTopMass1 = new TH1F("RecoTopMass1", "RecoTopMass1", 300, 0, 300);
  TH1F * histoRecoTopMass2 = new TH1F("RecoTopMass2", "RecoTopMass2", 300, 0, 300);
  TH2F * histoRecoTopMass1VsTopMass2 = new TH2F("RecoTopMass1VsTopMass2", "RecoTopMass1VsTopMass2", 300, 0, 300, 300, 0, 300);
  TH1F * histoRecoDelta_y = new TH1F("RecoDelta_y", "RecoDelta_y", 400, -2, 2);
  TH1F * histoRecoTTRapidity = new TH1F("RecoTTRapidity", "RecoTTRapidity", 500, -2.5, 2.5);
  TH1F * histoRecoTTPt = new TH1F("RecoTTPt", "RecoTTPt", 250, 0, 250);
  TH1F * histoRecoTTMass = new TH1F("RecoTTMass", "RecoTTMass", 100, 0, 1000);

  TH2F * histoRecoDelta_yVsTTRapidity = new TH2F("RecoDelta_yVsTTRapidity", "RecoDelta_yVsTTRapidity", 10, -2, 2, 5, -2.5, 2.5);
  TH2F * histoRecoDelta_yVsTTPt = new TH2F("RecoDelta_yVsTTPt", "RecoDelta_yVsTTPt", 10, -2, 2, 5, 0, 250);
  TH2F * histoRecoDelta_yVsTTMass = new TH2F("RecoDelta_yVsTTMass", "RecoDelta_yVsTTMass", 10, -2, 2, 5, 0, 1000);
  TH1F * histoRecoN_plusTTRapidity = new TH1F("RecoN_plusTTRapidity", "RecoN_plusTTRapidity", 20, -2.5, 2.5);
  histoRecoN_plusTTRapidity->Sumw2();
  TH1F * histoRecoN_plusTTPt = new TH1F("RecoN_plusTTPt", "RecoN_plusTTPt", 20, 0, 250);
  histoRecoN_plusTTPt->Sumw2();
  TH1F * histoRecoN_plusTTMass = new TH1F("RecoN_plusTTMass", "RecoN_plusTTMass", 20, 0, 1000);
  histoRecoN_plusTTMass->Sumw2();
  TH1F * histoRecoN_minusTTRapidity = new TH1F("RecoN_minusTTRapidity", "RecoN_minusTTRapidity", 20, -2.5, 2.5);
  histoRecoN_minusTTRapidity->Sumw2();
  TH1F * histoRecoN_minusTTPt = new TH1F("RecoN_minusTTPt", "RecoN_minusTTPt", 20, 0, 250);
  histoRecoN_minusTTPt->Sumw2();
  TH1F * histoRecoN_minusTTMass = new TH1F("RecoN_minusTTMass", "RecoN_minusTTMass", 20, 0, 1000);
  histoRecoN_minusTTMass->Sumw2();
  TH1F * histoRecoN_plusMinusN_minusTTRapidity = new TH1F("RecoN_plusMinusN_minusTTRapidity", "RecoN_plusMinusN_minusTTRapidity", 20, -2.5, 2.5);
  histoRecoN_plusMinusN_minusTTRapidity->Sumw2();
  TH1F * histoRecoN_plusPlusN_minusTTRapidity = new TH1F("RecoN_plusPlusN_minusTTRapidity", "RecoN_plusPlusN_minusTTRapidity", 20, -2.5, 2.5);
  histoRecoN_plusPlusN_minusTTRapidity->Sumw2();
  TH1F * histoRecoN_plusMinusN_minusTTPt = new TH1F("RecoN_plusMinusN_minusTTPt", "RecoN_plusMinusN_minusTTPt", 20, 0, 250);
  histoRecoN_plusMinusN_minusTTPt->Sumw2();
  TH1F * histoRecoN_plusPlusN_minusTTPt = new TH1F("RecoN_plusPlusN_minusTTPt", "RecoN_plusPlusN_minusTTPt", 20, 0, 250);
  histoRecoN_plusPlusN_minusTTPt->Sumw2();
  TH1F * histoRecoN_plusMinusN_minusTTMass = new TH1F("RecoN_plusMinusN_minusTTMass", "RecoN_plusMinusN_minusTTMass", 20, 0, 1000);
  histoRecoN_plusMinusN_minusTTMass->Sumw2();
  TH1F * histoRecoN_plusPlusN_minusTTMass = new TH1F("RecoN_plusPlusN_minusTTMass", "RecoN_plusPlusN_minusTTMass", 20, 0, 1000);
  histoRecoN_plusPlusN_minusTTMass->Sumw2();
  TH1F * histoRecoA_cTTRapidity = new TH1F("RecoA_cTTRapidity", "RecoA_cTTRapidity", 20, -2.5, 2.5);
  histoRecoA_cTTRapidity->Sumw2();
  TH1F * histoRecoA_cTTPt = new TH1F("RecoA_cTTPt", "RecoA_cTTPt", 20, 0, 250);
  histoRecoA_cTTPt->Sumw2();
  TH1F * histoRecoA_cTTMass = new TH1F("RecoA_cTTMass", "RecoA_cTTMass", 20, 0, 1000);
  histoRecoA_cTTMass->Sumw2();
  // Fine binning
  TH2F * histoFineBinning_RecoDelta_yVsTTRapidity = new TH2F("FineBinning_RecoDelta_yVsTTRapidity", "FineBinning_RecoDelta_yVsTTRapidity", 200, -2, 2, 500, -2.5, 2.5);
  TH2F * histoFineBinning_RecoDelta_yVsTTPt = new TH2F("FineBinning_RecoDelta_yVsTTPt", "FineBinning_RecoDelta_yVsTTPt", 200, -2, 2, 250, 0, 250);
  TH2F * histoFineBinning_RecoDelta_yVsTTMass = new TH2F("FineBinning_RecoDelta_yVsTTMass", "FineBinning_RecoDelta_yVsTTMass", 200, -2, 2, 100, 0, 1000);
  TH1F * histoFineBinning_RecoN_plusTTRapidity = new TH1F("FineBinning_RecoN_plusTTRapidity", "FineBinning_RecoN_plusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoN_plusTTRapidity->Sumw2();
  TH1F * histoFineBinning_RecoN_plusTTPt = new TH1F("FineBinning_RecoN_plusTTPt", "FineBinning_RecoN_plusTTPt", 250, 0, 250);
  histoFineBinning_RecoN_plusTTPt->Sumw2();
  TH1F * histoFineBinning_RecoN_plusTTMass = new TH1F("FineBinning_RecoN_plusTTMass", "FineBinning_RecoN_plusTTMass", 100, 0, 1000);
  histoFineBinning_RecoN_plusTTMass->Sumw2();
  TH1F * histoFineBinning_RecoN_minusTTRapidity = new TH1F("FineBinning_RecoN_minusTTRapidity", "FineBinning_RecoN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_RecoN_minusTTPt = new TH1F("FineBinning_RecoN_minusTTPt", "FineBinning_RecoN_minusTTPt", 250, 0, 250);
  histoFineBinning_RecoN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_RecoN_minusTTMass = new TH1F("FineBinning_RecoN_minusTTMass", "FineBinning_RecoN_minusTTMass", 100, 0, 1000);
  histoFineBinning_RecoN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_RecoN_plusMinusN_minusTTRapidity = new TH1F("FineBinning_RecoN_plusMinusN_minusTTRapidity", "FineBinning_RecoN_plusMinusN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Sumw2();  
  TH1F * histoFineBinning_RecoN_plusPlusN_minusTTRapidity = new TH1F("FineBinning_RecoN_plusPlusN_minusTTRapidity", "FineBinning_RecoN_plusPlusN_minusTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Sumw2();
  TH1F * histoFineBinning_RecoN_plusMinusN_minusTTPt = new TH1F("FineBinning_RecoN_plusMinusN_minusTTPt", "FineBinning_RecoN_plusMinusN_minusTTPt", 250, 0, 250);
  histoFineBinning_RecoN_plusMinusN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_RecoN_plusPlusN_minusTTPt = new TH1F("FineBinning_RecoN_plusPlusN_minusTTPt", "FineBinning_RecoN_plusPlusN_minusTTPt", 250, 0, 250);
  histoFineBinning_RecoN_plusPlusN_minusTTPt->Sumw2();
  TH1F * histoFineBinning_RecoN_plusMinusN_minusTTMass = new TH1F("FineBinning_RecoN_plusMinusN_minusTTMass", "FineBinning_RecoN_plusMinusN_minusTTMass", 100, 0, 1000);
  histoFineBinning_RecoN_plusMinusN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_RecoN_plusPlusN_minusTTMass = new TH1F("FineBinning_RecoN_plusPlusN_minusTTMass", "FineBinning_RecoN_plusPlusN_minusTTMass", 100, 0, 1000);
  histoFineBinning_RecoN_plusPlusN_minusTTMass->Sumw2();
  TH1F * histoFineBinning_RecoA_cTTRapidity = new TH1F("FineBinning_RecoA_cTTRapidity", "FineBinning_RecoA_cTTRapidity", 500, -2.5, 2.5);
  histoFineBinning_RecoA_cTTRapidity->Sumw2();
  TH1F * histoFineBinning_RecoA_cTTPt = new TH1F("FineBinning_RecoA_cTTPt", "FineBinning_RecoA_cTTPt", 250, 0, 250);
  histoFineBinning_RecoA_cTTPt->Sumw2();
  TH1F * histoFineBinning_RecoA_cTTMass = new TH1F("FineBinning_RecoA_cTTMass", "FineBinning_RecoA_cTTMass", 100, 0, 1000);
  histoFineBinning_RecoA_cTTMass->Sumw2();




  // RECO vs GEN
  TH2F * histoRecoVsGenTopRapidity1 = new TH2F("RecoVsGenTopRapidity1", "RecoVsGenTopRapidity1", 100, -5, 5, 100, -5, 5);
  TH2F * histoRecoVsGenTopRapidity2 = new TH2F("RecoVsGenTopRapidity2", "RecoVsGenTopRapidity2", 100, -5, 5, 100, -5, 5);
  TH2F * histoRecoVsGenTopMass1 = new TH2F("RecoVsGenTopMass1", "RecoVsGenTopMass1", 300, 0, 300, 200, 0, 200);
  TH2F * histoRecoVsGenTopMass2 = new TH2F("RecoVsGenTopMass2", "RecoVsGenTopMass2", 300, 0, 300, 200, 0, 200);
  TH1F * histoRecoMinusGenDivGenTopRapidity1 = new TH1F("RecoMinusGenDivGenTopRapidity1", "RecoMinusGenDivGenTopRapidity1", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenTopRapidity2 = new TH1F("RecoMinusGenDivGenTopRapidity2", "RecoMinusGenDivGenTopRapidity2", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenLeptonRapidity1 = new TH1F("RecoMinusGenDivGenLeptonRapidity1", "RecoMinusGenDivGenLeptonRapidity1", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenLeptonRapidity2 = new TH1F("RecoMinusGenDivGenLeptonRapidity2", "RecoMinusGenDivGenLeptonRapidity2", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenTopMass1 = new TH1F("RecoMinusGenDivGenTopMass1", "RecoMinusGenDivGenTopMass1", 100, -3, 3);
  TH1F * histoRecoMinusGenDivGenTopMass2 = new TH1F("RecoMinusGenDivGenTopMass2", "RecoMinusGenDivGenTopMass2", 100, -3, 3);

  TH2F * histoFineBinning_RecoVsGenDelta_y = new TH2F("FineBinning_RecoVsGenDelta_y", "FineBinning_RecoVsGenDelta_y", 400, -2, 2, 400, -2, 2); // Migration Matrix
  TH2F * histoRecoVsGenDelta_y = new TH2F("RecoVsGenDelta_y", "RecoVsGenDelta_y", 8, -2, 2, 16, -2, 2); // Migration Matrix
  TH1F * histoRecoMinusGenDivGenDelta_y = new TH1F("RecoMinusGenDivGenDelta_y", "RecoMinusGenDivGenDelta_y", 100, -3, 3);

  TH2F * histoRecoVsGenTTRapidity = new TH2F("RecoVsGenTTRapidity", "RecoVsGenTTRapidity", 500, -2.5, 2.5, 500, -2.5, 2.5);
  TH1F * histoRecoMinusGenDivGenTTRapidity = new TH1F("RecoMinusGenDivGenTTRapidity", "RecoMinusGenDivGenTTRapidity", 100, -3, 3);
  TH2F * histoRecoVsGenTTPt = new TH2F("RecoVsGenTTPt", "RecoVsGenTTPt", 250, 0, 250, 250, 0, 250);
  TH1F * histoRecoMinusGenDivGenTTPt = new TH1F("RecoMinusGenDivGenTTPt", "RecoMinusGenDivGenTTPt", 100, -3, 3);
  TH2F * histoRecoVsGenTTMass = new TH2F("RecoVsGenTTMass", "RecoVsGenTTMass", 100, 0, 1000, 100, 0, 1000);
  TH1F * histoRecoMinusGenDivGenTTMass = new TH1F("RecoMinusGenDivGenTTMass", "RecoMinusGenDivGenTTMass", 100, -3, 3);

  TH1F * histoDelta_yEfficiencyN = new TH1F("Delta_yEfficiencyN", "Delta_yEfficiencyN", 10, -2, 2);
  TH1F * histoDelta_yEfficiencyD = new TH1F("Delta_yEfficiencyD", "Delta_yEfficiencyD", 10, -2, 2);
  TH1F * histoDelta_yEfficiency = new TH1F("Delta_yEfficiency", "Delta_yEfficiency", 10, -2, 2);

  TH2F * histoDelta_yVsTTRapidityEfficiency = new TH2F("Delta_yVsTTRapidityEfficiency", "Delta_yVsTTRapidityEfficiency", 10, -2, 2, 5, -2.5, 2.5);
  TH2F * histoDelta_yVsTTPtEfficiency = new TH2F("Delta_yVsTTPtEfficiency", "Delta_yVsTTPtEfficiency", 10, -2, 2, 5, 0, 250);
  TH2F * histoDelta_yVsTTMassEfficiency = new TH2F("Delta_yVsTTMassEfficiency", "Delta_yVsTTMassEfficiency", 10, -2, 2, 5, 0, 1000);
  // Fine binning
  TH1F * histoFineBinning_Delta_yEfficiencyN = new TH1F("FineBinning_Delta_yEfficiencyN", "FineBinning_Delta_yEfficiencyN", 200, -2, 2);
  TH1F * histoFineBinning_Delta_yEfficiencyD = new TH1F("FineBinning_Delta_yEfficiencyD", "FineBinning_Delta_yEfficiencyD", 200, -2, 2);
  TH1F * histoFineBinning_Delta_yEfficiency = new TH1F("FineBinning_Delta_yEfficiency", "FineBinning_Delta_yEfficiency", 200, -2, 2);

  TH2F * histoFineBinning_Delta_yVsTTRapidityEfficiency = new TH2F("FineBinning_Delta_yVsTTRapidityEfficiency", "FineBinning_Delta_yVsTTRapidityEfficiency", 200, -2, 2, 500, -2.5, 2.5);
  TH2F * histoFineBinning_Delta_yVsTTPtEfficiency = new TH2F("FineBinning_Delta_yVsTTPtEfficiency", "FineBinning_Delta_yVsTTPtEfficiency", 200, -2, 2, 250, 0, 250);
  TH2F * histoFineBinning_Delta_yVsTTMassEfficiency = new TH2F("FineBinning_Delta_yVsTTMassEfficiency", "FineBinning_Delta_yVsTTMassEfficiency", 200, -2, 2, 100, 0, 1000);




  vector < Dataset > datasets;
  DiLeptonSelection sel;
  float Luminosity = 0;
  // 0: MC - 1: Data - 2 Data & MC
  int DataType = 0;
  int verbosity = -1;
  
  // Analysis variables
  int step;
  //4-vectors
  vector < TLorentzVector > nu1;
  vector < TLorentzVector > nu2;
  //  TLorentzVector lvTop1_aux;
  //TLorentzVector lvTop2_aux;

  //////////////////////

  //////////////////////
  // Initialisation
  //////////////////////
  AnalysisEnvironmentLoader anaEL (xmlFileName);
  anaEL.LoadSamples (datasets); // now the list of datasets written in the xml file is known
  anaEL.LoadDiLeptonSelection (sel); // now the parameters for the selection are given to the selection
  anaEL.LoadGeneralInfo(DataType, Luminosity, verbosity );

  float weight_MC; 
  int nEvents;
  int firstEvent;
  int initialEvents;
  anaEL.LoadAnalysisInfo("Run", "firstEvent", firstEvent);
  anaEL.LoadAnalysisInfo("Run", "nEvents", nEvents);
  anaEL.LoadAnalysisInfo("Run", "initialEvents", initialEvents);
  string channelName;
  anaEL.LoadAnalysisInfo("MassAnalysis", "ChannelName", channelName);

  anaEL.LoadWeight (sel); // now the parameters for SFBweight are initialized (for b-tag!)

  //******************************************
  //Load Scale Factors for lepton efficiencies
  //******************************************
  sel.LoadElScaleFactors();
  sel.LoadMuScaleFactors();
  sel.InitJESUnc();

  bool nonskimmed = false;

  TopTree::NTEvent * event = 0;

  TFile * TupleFile = new TFile("TupleFileSkimmed_TTbarSignalMadgraph_LeptonSelEffNegLeptonWithMinus_btag.root","RECREATE");
  float mttbar_rec, mttbar_gen;
  float diffysquare_rec, diffysquare_gen;
  float diffabseta_rec, diffabseta_gen;
  float weight;
  float pt_ttbar, pt_ttbar_gen;
  float pz_ttbar, pz_ttbar_gen;
  float eta_ttbar_rec, eta_ttbar_gen;
  float y_ttbar_rec, y_ttbar_gen;
  float diffabsy_rec, diffabsy_gen;

  TTree *tree = new TTree("Tuple","Tuple");
  tree->Branch("mttbar_rec",&mttbar_rec,"mttbar_rec/F");
  tree->Branch("mttbar_gen",&mttbar_gen,"mttbar_gen/F");
  tree->Branch("diffysquare_rec",&diffysquare_rec,"diffysquare_rec/F");
  tree->Branch("diffysquare_gen",&diffysquare_gen,"diffysquare_gen/F");
  tree->Branch("diffabseta_rec",&diffabseta_rec,"diffabseta_rec/F");
  tree->Branch("diffabseta_gen",&diffabseta_gen,"diffabseta_gen/F");
  tree->Branch("weight",&weight,"weight/F");
  tree->Branch("pt_ttbar",&pt_ttbar,"pt_ttbar/F");
  tree->Branch("pt_ttbar_gen",&pt_ttbar_gen,"pt_ttbar_gen/F");
  tree->Branch("pz_ttbar",&pz_ttbar,"pz_ttbar/F");
  tree->Branch("pz_ttbar_gen",&pz_ttbar_gen,"pz_ttbar_gen/F");
  tree->Branch("eta_ttbar_rec",&eta_ttbar_rec,"eta_ttbar_rec/F");
  tree->Branch("eta_ttbar_gen",&eta_ttbar_gen,"eta_ttbar_gen/F");
  tree->Branch("y_ttbar_rec",&y_ttbar_rec,"y_ttbar_rec/F");
  tree->Branch("y_ttbar_gen",&y_ttbar_gen,"y_ttbar_gen/F");
  tree->Branch("diffabsy_rec",&diffabsy_rec,"diffabsy_rec/F");
  tree->Branch("diffabsy_gen",&diffabsy_gen,"diffabsy_gen/F");

  //////////////////////
  //LOOP OVER THE DATASETS
  //////////////////////
  if(verbosity>0) {
    cout<<"#########################"<<endl;
    cout<<" Loop over the datasets  "<<endl;
    cout<<"#########################"<<endl;
  }

  float num_mttbar_eff = 0.;
  float den_mttbar_eff = 0.;

  for (unsigned int d = 0; d < datasets.size (); d++) {

    weight_MC = datasets[d].NormFactor()*Luminosity;

    if(datasets[d].isData() == true) weight_MC = 1.; cout << "isDATA" << endl;

    AMWT amwt(anaEL, datasets[d].isData());

    TString sample_name(datasets[d].Name());


    bool isData = datasets[d].isData ();
    datasets[d].eventTree ()->SetBranchAddress ("NTEvent",&event);
    
    cout << "Sample : " << sample_name<< endl;
    cout << "Data   : " << isData<< endl;

    unsigned int nEventsSample = (int) (datasets[d].eventTree ()->GetEntries ());
    unsigned int endEventToRun;

    if (firstEvent>nEventsSample) firstEvent = nEventsSample;
    if ((nEvents==-1)||((nEvents+firstEvent)>nEventsSample)) endEventToRun = nEventsSample;
    else endEventToRun = nEvents+firstEvent;
    cout << "Events to run: number / first / last / all: " << endEventToRun-firstEvent 
         << " / " << firstEvent << " / " << endEventToRun
         << " / " << nEventsSample << endl;

// Standard parameters for doFullSelection:

    bool applyEEScale = false; float EEScaleParam = 1.; bool applyEEResol = false; float EEResolParam = 1.;
    bool applyMEScale = false; float MEScaleParam = 1.; bool applyMEResol = false; float MEResolParam = 1.;
    bool applyMETS = false; float METScale = 1.;
    bool applyJES = false; float JESParam = 1.;
    bool applyJER = false; float JERFactor = 0.; 

    //////////////////////
    //LOOP OVER THE EVENTS
    //////////////////////

    float N_plus_reco = 0;
    float N_minus_reco = 0;

    float N_plus_gen = 0;
    float N_minus_gen = 0;

    mttbar_rec = 0;
    mttbar_gen = 0;
    diffysquare_rec = 0;
    diffysquare_gen = 0;
    diffabseta_rec = 0;
    diffabseta_gen = 0;
    weight = weight_MC;
    pt_ttbar = 0;
    pt_ttbar_gen = 0;
    pz_ttbar = 0;
    pz_ttbar_gen = 0;
    eta_ttbar_rec = 0;
    eta_ttbar_gen = 0;
    y_ttbar_rec = 0;
    y_ttbar_gen = 0;
    diffabsy_rec = 0;
    diffabsy_gen = 0;

    for (unsigned int ievt = firstEvent; ievt < endEventToRun; ievt++) {
//           for (unsigned int ievt = 0; ievt < 10; ievt++) {

      datasets[d].eventTree ()->GetEntry (ievt);




      if(ievt%1000 == 0) cout << "number of processed events " << ievt << endl;
      if (verbosity >= 1) cout << "Event : "<< event->runNb<<" , " << event->lumiblock <<" , " << event->eventNb<<endl;

      if(!(event->TMEME == 2  || event->TMEME == 10101 || event->TMEME == 20200 || event->TMEME == 20 || event->TMEME == 11010 || 
event->TMEME == 22000|| event->TMEME == 11 || event->TMEME == 11001 || event->TMEME == 10110 || event->TMEME == 21100 )) continue;

      string candType;
      vector<NTElectron> candElec;
      vector<NTMuon> candMuon;

      //Load event for the selection
      sel.LoadEvent(event);

      int finalCut = sel.doFullSelection(&(datasets[d]), channelName, false, /*print*/ verbosity,
	false, false, -1., -1., applyJES,  JESParam,
	 applyEEScale,  EEScaleParam,  applyEEResol,  EEResolParam,
	 applyMEScale,  MEScaleParam,  
	 applyJER,  JERFactor,  applyMETS,  METScale);




        TLorentzVector lvTop1_gen;
        TLorentzVector lvTop2_gen;
        TLorentzVector lvTop1plusTop2_gen;
        float yt_gen = 0.;
        float ytbar_gen = 0.;
        float Delta_y_gen = 0.;

        if(datasets[d].Name() == "TTJets_Sig"){


        lvTop1_gen = (event->topAndDecays)[0].p4_t_gen;
        lvTop2_gen = (event->topAndDecays)[1].p4_t_gen;
        lvTop1plusTop2_gen = lvTop1_gen + lvTop2_gen;

        /////////////////////////
        //// GENERATOR LEVEL ////
        /////////////////////////

        histoGenTopRapidity1->Fill(lvTop1_gen.Rapidity());
        histoGenTopRapidity2->Fill(lvTop2_gen.Rapidity());
        histoGenTopMass1->Fill(lvTop1_gen.M());
        histoGenTopMass2->Fill(lvTop2_gen.M());
        histoGenTopMass1VsTopMass2->Fill(lvTop1_gen.M(),lvTop2_gen.M());

        yt_gen = lvTop1_gen.Rapidity();
        if(yt_gen<0.) yt_gen = (-1)*yt_gen;
        ytbar_gen = lvTop2_gen.Rapidity();
        if(ytbar_gen<0.) ytbar_gen = (-1)*ytbar_gen;
        Delta_y_gen = yt_gen - ytbar_gen;
	//        cout << "Delta_y_gen:" << Delta_y_gen << endl;
        histoGenDelta_y->Fill(Delta_y_gen);
        histoDelta_yEfficiencyD->Fill(Delta_y_gen);
        histoFineBinning_Delta_yEfficiencyD->Fill(Delta_y_gen);

        if(Delta_y_gen>0.){
          N_plus_gen++;
          histoGenN_plusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
          histoGenN_plusTTPt->Fill(lvTop1plusTop2_gen.Perp());
          histoGenN_plusTTMass->Fill(lvTop1plusTop2_gen.M());
          histoFineBinning_GenN_plusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
          histoFineBinning_GenN_plusTTPt->Fill(lvTop1plusTop2_gen.Perp());
          histoFineBinning_GenN_plusTTMass->Fill(lvTop1plusTop2_gen.M());
	}

        if(Delta_y_gen<0.){
          N_minus_gen++;
          histoGenN_minusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
          histoGenN_minusTTPt->Fill(lvTop1plusTop2_gen.Perp());
          histoGenN_minusTTMass->Fill(lvTop1plusTop2_gen.M());
          histoFineBinning_GenN_minusTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
          histoFineBinning_GenN_minusTTPt->Fill(lvTop1plusTop2_gen.Perp());
          histoFineBinning_GenN_minusTTMass->Fill(lvTop1plusTop2_gen.M());

	}

        histoGenTTRapidity->Fill(lvTop1plusTop2_gen.Rapidity());
        histoGenTTPt->Fill(lvTop1plusTop2_gen.Perp());
        histoGenTTMass->Fill(lvTop1plusTop2_gen.M());
        histoGenDelta_yVsTTRapidity->Fill(Delta_y_gen, lvTop1plusTop2_gen.Rapidity());
        histoGenDelta_yVsTTPt->Fill(Delta_y_gen, lvTop1plusTop2_gen.Perp());
        histoGenDelta_yVsTTMass->Fill(Delta_y_gen, lvTop1plusTop2_gen.M());

        histoFineBinning_GenDelta_yVsTTRapidity->Fill(Delta_y_gen, lvTop1plusTop2_gen.Rapidity());
        histoFineBinning_GenDelta_yVsTTPt->Fill(Delta_y_gen, lvTop1plusTop2_gen.Perp());
        histoFineBinning_GenDelta_yVsTTMass->Fill(Delta_y_gen, lvTop1plusTop2_gen.M());


        if(nonskimmed == true){
         mttbar_gen = lvTop1plusTop2_gen.M();
         diffysquare_gen = yt_gen*yt_gen - ytbar_gen*ytbar_gen;
         diffabseta_gen = fabs(lvTop1_gen.Eta()) - fabs(lvTop2_gen.Eta());
         pt_ttbar_gen = lvTop1plusTop2_gen.Perp();
         pz_ttbar_gen = lvTop1plusTop2_gen.Pz();
         eta_ttbar_gen = lvTop1plusTop2_gen.Eta();
         y_ttbar_gen = lvTop1plusTop2_gen.Rapidity();
         diffabsy_gen = fabs(lvTop1_gen.Rapidity()) - fabs(lvTop2_gen.Rapidity());
	}

	}

      if (finalCut >6) {

        if(nonskimmed == false){
         if(datasets[d].Name() == "TTJets_Sig"){
         mttbar_gen = lvTop1plusTop2_gen.M();
         diffysquare_gen = yt_gen*yt_gen - ytbar_gen*ytbar_gen;
         diffabseta_gen = fabs(lvTop1_gen.Eta()) - fabs(lvTop2_gen.Eta());
         pt_ttbar_gen = lvTop1plusTop2_gen.Perp();
         pz_ttbar_gen = lvTop1plusTop2_gen.Pz();
         eta_ttbar_gen = lvTop1plusTop2_gen.Eta();
         y_ttbar_gen = lvTop1plusTop2_gen.Rapidity();
         diffabsy_gen = fabs(lvTop1_gen.Rapidity()) - fabs(lvTop2_gen.Rapidity());
	 }
	}

        sel.GetLeptonPair(candMuon, candElec, candType);

        for(unsigned int i=0; i<candMuon.size(); i++){
          if(candMuon[i].Charge == +1) histoRecoLeptonRapidity1->Fill(candMuon[i].p4.Rapidity());
          if(candMuon[i].Charge == -1) histoRecoLeptonRapidity2->Fill(candMuon[i].p4.Rapidity());
	}

        for(unsigned int j=0; j<candElec.size(); j++){
          if(candElec[j].Charge == +1) histoRecoLeptonRapidity1->Fill(candElec[j].p4.Rapidity());
          if(candElec[j].Charge == -1) histoRecoLeptonRapidity2->Fill(candElec[j].p4.Rapidity());
	}

        for(unsigned int i=0; i<candMuon.size(); i++){
          if (candMuon[i].Charge == -1) weight *= 1 + (0.01 - 2 * 0.01 * fabs(candMuon[i].p4.PseudoRapidity() / 2.1))/2;
	  if (candMuon[i].Charge == +1) weight *= 1 - (0.01 + 2 * 0.01 * fabs(candMuon[i].p4.PseudoRapidity() / 2.1))/2;
        }

        for(unsigned int i=0; i<candElec.size(); i++){
          if (candElec[i].Charge == -1) weight *= 1 + (0.02 - 2 * 0.02 * fabs(candElec[i].p4.PseudoRapidity() / 2.5))/2;
	  if (candElec[i].Charge == +1) weight *= 1 - (0.02 + 2 * 0.02 * fabs(candElec[i].p4.PseudoRapidity() / 2.5))/2;
        }

        TLorentzVector lvTop1_reco;
        TLorentzVector lvTop2_reco;
        TLorentzVector lvTop1plusTop2_reco;


        TopMassVariables * tmv = amwt.findMass(sel, lvTop1_reco, lvTop2_reco);
        lvTop1plusTop2_reco = lvTop1_reco + lvTop2_reco;



        ////////////////////
        /// RECO LEVEL /////
        ////////////////////

        histoRecoTopRapidity1->Fill(lvTop1_reco.Rapidity());
        histoRecoTopRapidity2->Fill(lvTop2_reco.Rapidity());
        histoRecoTopMass1->Fill(lvTop1_reco.M());
        histoRecoTopMass2->Fill(lvTop2_reco.M());
        histoRecoTopMass1VsTopMass2->Fill(lvTop1_reco.M(),lvTop2_reco.M());

        float yt_reco = lvTop1_reco.Rapidity();
        if(yt_reco<0.) yt_reco = (-1)*yt_reco;
        float ytbar_reco = lvTop2_reco.Rapidity();
        if(ytbar_reco<0.) ytbar_reco = (-1)*ytbar_reco;
        float Delta_y_reco = yt_reco - ytbar_reco;
	//        cout << "Delta_y_reco:" << Delta_y_reco << endl;
        histoRecoDelta_y->Fill(Delta_y_reco);
        histoDelta_yEfficiencyN->Fill(Delta_y_reco);
        histoFineBinning_Delta_yEfficiencyN->Fill(Delta_y_reco);

        if(Delta_y_reco>0.){
          N_plus_reco++;
          histoRecoN_plusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
          histoRecoN_plusTTPt->Fill(lvTop1plusTop2_reco.Perp());
          histoRecoN_plusTTMass->Fill(lvTop1plusTop2_reco.M());
          histoFineBinning_RecoN_plusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
          histoFineBinning_RecoN_plusTTPt->Fill(lvTop1plusTop2_reco.Perp());
          histoFineBinning_RecoN_plusTTMass->Fill(lvTop1plusTop2_reco.M());
	}

        if(Delta_y_reco<0.){
          N_minus_reco++;
          histoRecoN_minusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
          histoRecoN_minusTTPt->Fill(lvTop1plusTop2_reco.Perp());
          histoRecoN_minusTTMass->Fill(lvTop1plusTop2_reco.M());
          histoFineBinning_RecoN_minusTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
          histoFineBinning_RecoN_minusTTPt->Fill(lvTop1plusTop2_reco.Perp());
          histoFineBinning_RecoN_minusTTMass->Fill(lvTop1plusTop2_reco.M());
	}

        histoRecoTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity());
        histoRecoTTPt->Fill(lvTop1plusTop2_reco.Perp());
        histoRecoTTMass->Fill(lvTop1plusTop2_reco.M());
        histoRecoDelta_yVsTTRapidity->Fill(Delta_y_reco, lvTop1plusTop2_reco.Rapidity());
        histoRecoDelta_yVsTTPt->Fill(Delta_y_reco, lvTop1plusTop2_reco.Perp());
        histoRecoDelta_yVsTTMass->Fill(Delta_y_reco, lvTop1plusTop2_reco.M());

        histoFineBinning_RecoDelta_yVsTTRapidity->Fill(Delta_y_reco, lvTop1plusTop2_reco.Rapidity());
        histoFineBinning_RecoDelta_yVsTTPt->Fill(Delta_y_reco, lvTop1plusTop2_reco.Perp());
        histoFineBinning_RecoDelta_yVsTTMass->Fill(Delta_y_reco, lvTop1plusTop2_reco.M());

        if(nonskimmed == false){

         mttbar_rec = lvTop1plusTop2_reco.M();
         diffysquare_rec = yt_reco*yt_reco - ytbar_reco*ytbar_reco;
         diffabseta_rec = fabs(lvTop1_reco.Eta()) - fabs(lvTop2_reco.Eta());
         pt_ttbar = lvTop1plusTop2_reco.Perp();
         pz_ttbar = lvTop1plusTop2_reco.Pz();
         eta_ttbar_rec = lvTop1plusTop2_reco.Eta();
         y_ttbar_rec = lvTop1plusTop2_reco.Rapidity();
         diffabsy_rec = fabs(lvTop1_reco.Rapidity()) - fabs(lvTop2_reco.Rapidity());

	}

        ////////////////////////
        // RECO VS GEN LEVEL ///
        ////////////////////////
        if(datasets[d].Name() == "TTJets_Sig"){
 
        histoRecoVsGenTopRapidity1->Fill(lvTop1_reco.Rapidity(), lvTop1_gen.Rapidity());
        histoRecoVsGenTopRapidity2->Fill(lvTop2_reco.Rapidity(), lvTop2_gen.Rapidity());
        histoRecoVsGenTopMass1->Fill(lvTop1_reco.M(), lvTop1_gen.M());
        histoRecoVsGenTopMass2->Fill(lvTop2_reco.M(), lvTop2_gen.M());
	histoRecoMinusGenDivGenTopRapidity1->Fill((lvTop1_reco.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity());
        histoRecoMinusGenDivGenTopRapidity2->Fill((lvTop2_reco.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity());

        for(unsigned int i=0; i<candMuon.size(); i++){
          if(candMuon[i].Charge == +1) histoRecoMinusGenDivGenLeptonRapidity1->Fill((candMuon[i].p4.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity());
          if(candMuon[i].Charge == -1) histoRecoMinusGenDivGenLeptonRapidity2->Fill((candMuon[i].p4.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity());
	}

        for(unsigned int j=0; j<candElec.size(); j++){
          if(candElec[j].Charge == +1) histoRecoMinusGenDivGenLeptonRapidity1->Fill((candElec[j].p4.Rapidity() - lvTop1_gen.Rapidity())/lvTop1_gen.Rapidity());
          if(candElec[j].Charge == -1) histoRecoMinusGenDivGenLeptonRapidity2->Fill((candElec[j].p4.Rapidity() - lvTop2_gen.Rapidity())/lvTop2_gen.Rapidity());
	}

	histoRecoMinusGenDivGenTopMass1->Fill((lvTop1_reco.M() - lvTop1_gen.M())/lvTop1_gen.M());
        histoRecoMinusGenDivGenTopMass2->Fill((lvTop2_reco.M() - lvTop2_gen.M())/lvTop2_gen.M());

        histoRecoVsGenDelta_y->Fill(Delta_y_reco, Delta_y_gen);
        histoFineBinning_RecoVsGenDelta_y->Fill(Delta_y_reco, Delta_y_gen);
        histoRecoMinusGenDivGenDelta_y->Fill((Delta_y_reco - Delta_y_gen)/Delta_y_gen);

        histoRecoVsGenTTRapidity->Fill(lvTop1plusTop2_reco.Rapidity(),lvTop1plusTop2_gen.Rapidity());
        histoRecoMinusGenDivGenTTRapidity->Fill((lvTop1plusTop2_reco.Rapidity() - lvTop1plusTop2_gen.Rapidity())/lvTop1plusTop2_gen.Rapidity());
        histoRecoVsGenTTPt->Fill(lvTop1plusTop2_reco.Perp(),lvTop1plusTop2_gen.Perp());
        histoRecoMinusGenDivGenTTPt->Fill((lvTop1plusTop2_reco.Perp() - lvTop1plusTop2_gen.Perp())/lvTop1plusTop2_gen.Perp());
        histoRecoVsGenTTMass->Fill(lvTop1plusTop2_reco.M(),lvTop1plusTop2_gen.M());
        histoRecoMinusGenDivGenTTMass->Fill((lvTop1plusTop2_reco.M() - lvTop1plusTop2_gen.M())/lvTop1plusTop2_gen.M());

	}

	//	tmv->printAll();
	delete tmv;
       if(nonskimmed == false && mttbar_rec > 60.){ tree->Fill(); num_mttbar_eff += weight_MC;}
       if(nonskimmed == false) den_mttbar_eff += weight_MC;
      }

      if(nonskimmed == true) tree->Fill();

    }  // end of loop over evts

    float A_C_reco = (N_plus_reco - N_minus_reco)/(N_plus_reco + N_minus_reco);
    float A_C_gen = (N_plus_gen - N_minus_gen)/(N_plus_gen + N_minus_gen);

    cout << "A_C_gen:" << A_C_gen << endl;
    cout << "A_C_reco:" << A_C_reco << endl;

    histoGenN_plusMinusN_minusTTRapidity->Add(histoGenN_plusTTRapidity);
    histoGenN_plusMinusN_minusTTRapidity->Add(histoGenN_minusTTRapidity,-1);
    histoGenN_plusPlusN_minusTTRapidity->Add(histoGenN_plusTTRapidity);
    histoGenN_plusPlusN_minusTTRapidity->Add(histoGenN_minusTTRapidity);

    histoGenA_cTTRapidity->Divide(histoGenN_plusMinusN_minusTTRapidity, histoGenN_plusPlusN_minusTTRapidity);

    histoGenN_plusMinusN_minusTTPt->Add(histoGenN_plusTTPt);
    histoGenN_plusMinusN_minusTTPt->Add(histoGenN_minusTTPt,-1);
    histoGenN_plusPlusN_minusTTPt->Add(histoGenN_plusTTPt);
    histoGenN_plusPlusN_minusTTPt->Add(histoGenN_minusTTPt);

    histoGenA_cTTPt->Divide(histoGenN_plusMinusN_minusTTPt, histoGenN_plusPlusN_minusTTPt);

    histoGenN_plusMinusN_minusTTMass->Add(histoGenN_plusTTMass);
    histoGenN_plusMinusN_minusTTMass->Add(histoGenN_minusTTMass,-1);
    histoGenN_plusPlusN_minusTTMass->Add(histoGenN_plusTTMass);
    histoGenN_plusPlusN_minusTTMass->Add(histoGenN_minusTTMass);

    histoGenA_cTTMass->Divide(histoGenN_plusMinusN_minusTTMass, histoGenN_plusPlusN_minusTTMass);

    histoRecoN_plusMinusN_minusTTRapidity->Add(histoRecoN_plusTTRapidity);
    histoRecoN_plusMinusN_minusTTRapidity->Add(histoRecoN_minusTTRapidity,-1);
    histoRecoN_plusPlusN_minusTTRapidity->Add(histoRecoN_plusTTRapidity);
    histoRecoN_plusPlusN_minusTTRapidity->Add(histoRecoN_minusTTRapidity);

    histoRecoA_cTTRapidity->Divide(histoRecoN_plusMinusN_minusTTRapidity, histoRecoN_plusPlusN_minusTTRapidity);

    histoRecoN_plusMinusN_minusTTPt->Add(histoRecoN_plusTTPt);
    histoRecoN_plusMinusN_minusTTPt->Add(histoRecoN_minusTTPt,-1);
    histoRecoN_plusPlusN_minusTTPt->Add(histoRecoN_plusTTPt);
    histoRecoN_plusPlusN_minusTTPt->Add(histoRecoN_minusTTPt);

    histoRecoA_cTTPt->Divide(histoRecoN_plusMinusN_minusTTPt, histoRecoN_plusPlusN_minusTTPt);

    histoRecoN_plusMinusN_minusTTMass->Add(histoRecoN_plusTTMass);
    histoRecoN_plusMinusN_minusTTMass->Add(histoRecoN_minusTTMass,-1);
    histoRecoN_plusPlusN_minusTTMass->Add(histoRecoN_plusTTMass);
    histoRecoN_plusPlusN_minusTTMass->Add(histoRecoN_minusTTMass);

    histoRecoA_cTTMass->Divide(histoRecoN_plusMinusN_minusTTMass, histoRecoN_plusPlusN_minusTTMass);





    histoFineBinning_GenN_plusMinusN_minusTTRapidity->Add(histoFineBinning_GenN_plusTTRapidity);
    histoFineBinning_GenN_plusMinusN_minusTTRapidity->Add(histoFineBinning_GenN_minusTTRapidity,-1);
    histoFineBinning_GenN_plusPlusN_minusTTRapidity->Add(histoFineBinning_GenN_plusTTRapidity);
    histoFineBinning_GenN_plusPlusN_minusTTRapidity->Add(histoFineBinning_GenN_minusTTRapidity);

    histoFineBinning_GenA_cTTRapidity->Divide(histoFineBinning_GenN_plusMinusN_minusTTRapidity, histoFineBinning_GenN_plusPlusN_minusTTRapidity);

    histoFineBinning_GenN_plusMinusN_minusTTPt->Add(histoFineBinning_GenN_plusTTPt);
    histoFineBinning_GenN_plusMinusN_minusTTPt->Add(histoFineBinning_GenN_minusTTPt,-1);
    histoFineBinning_GenN_plusPlusN_minusTTPt->Add(histoFineBinning_GenN_plusTTPt);
    histoFineBinning_GenN_plusPlusN_minusTTPt->Add(histoFineBinning_GenN_minusTTPt);

    histoFineBinning_GenA_cTTPt->Divide(histoFineBinning_GenN_plusMinusN_minusTTPt, histoFineBinning_GenN_plusPlusN_minusTTPt);

    histoFineBinning_GenN_plusMinusN_minusTTMass->Add(histoFineBinning_GenN_plusTTMass);
    histoFineBinning_GenN_plusMinusN_minusTTMass->Add(histoFineBinning_GenN_minusTTMass,-1);
    histoFineBinning_GenN_plusPlusN_minusTTMass->Add(histoFineBinning_GenN_plusTTMass);
    histoFineBinning_GenN_plusPlusN_minusTTMass->Add(histoFineBinning_GenN_minusTTMass);

    histoFineBinning_GenA_cTTMass->Divide(histoFineBinning_GenN_plusMinusN_minusTTMass, histoFineBinning_GenN_plusPlusN_minusTTMass);

    histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Add(histoFineBinning_RecoN_plusTTRapidity);
    histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Add(histoFineBinning_RecoN_minusTTRapidity,-1);
    histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Add(histoFineBinning_RecoN_plusTTRapidity);
    histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Add(histoFineBinning_RecoN_minusTTRapidity);

    histoFineBinning_RecoA_cTTRapidity->Divide(histoFineBinning_RecoN_plusMinusN_minusTTRapidity, histoFineBinning_RecoN_plusPlusN_minusTTRapidity);

    histoFineBinning_RecoN_plusMinusN_minusTTPt->Add(histoFineBinning_RecoN_plusTTPt);
    histoFineBinning_RecoN_plusMinusN_minusTTPt->Add(histoFineBinning_RecoN_minusTTPt,-1);
    histoFineBinning_RecoN_plusPlusN_minusTTPt->Add(histoFineBinning_RecoN_plusTTPt);
    histoFineBinning_RecoN_plusPlusN_minusTTPt->Add(histoFineBinning_RecoN_minusTTPt);

    histoFineBinning_RecoA_cTTPt->Divide(histoFineBinning_RecoN_plusMinusN_minusTTPt, histoFineBinning_RecoN_plusPlusN_minusTTPt);

    histoFineBinning_RecoN_plusMinusN_minusTTMass->Add(histoFineBinning_RecoN_plusTTMass);
    histoFineBinning_RecoN_plusMinusN_minusTTMass->Add(histoFineBinning_RecoN_minusTTMass,-1);
    histoFineBinning_RecoN_plusPlusN_minusTTMass->Add(histoFineBinning_RecoN_plusTTMass);
    histoFineBinning_RecoN_plusPlusN_minusTTMass->Add(histoFineBinning_RecoN_minusTTMass);

    histoFineBinning_RecoA_cTTMass->Divide(histoFineBinning_RecoN_plusMinusN_minusTTMass, histoFineBinning_RecoN_plusPlusN_minusTTMass);



    histoDelta_yEfficiency->Divide(histoDelta_yEfficiencyN, histoDelta_yEfficiencyD);
    histoFineBinning_Delta_yEfficiency->Divide(histoFineBinning_Delta_yEfficiencyN, histoFineBinning_Delta_yEfficiencyD);


    for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) {
     for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) {
       float value = histoRecoDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2);
       histoDelta_yVsTTRapidityEfficiency->SetBinContent(bin_index1, bin_index2, value);
       float value_fb = histoFineBinning_RecoDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTRapidity->GetBinContent(bin_index1,bin_index2);
       histoFineBinning_Delta_yVsTTRapidityEfficiency->SetBinContent(bin_index1, bin_index2, value_fb);

     }
    }

    for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) {
     for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) {
       float value = histoRecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2);
       histoDelta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value);
       float value_fb = histoFineBinning_RecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2);
       histoFineBinning_Delta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value_fb);

     }
    }


    for (unsigned int bin_index1 = 1; bin_index1 < 11; bin_index1++) {
     for (unsigned int bin_index2 = 1; bin_index2 < 6; bin_index2++) {
       float value = histoRecoDelta_yVsTTMass->GetBinContent(bin_index1,bin_index2)/histoGenDelta_yVsTTMass->GetBinContent(bin_index1,bin_index2);
       histoDelta_yVsTTMassEfficiency->SetBinContent(bin_index1, bin_index2, value);
       float value_fb = histoFineBinning_RecoDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2)/histoFineBinning_GenDelta_yVsTTPt->GetBinContent(bin_index1,bin_index2);
       histoFineBinning_Delta_yVsTTPtEfficiency->SetBinContent(bin_index1, bin_index2, value_fb);

     }
    }






  }				// end of loop over the datasets


//  if(verbosity>0) {



    cout<<"#########################"<<endl;
    cout<<"    End of the program   "<<endl;
    cout<<"#########################"<<endl;
//  }

    tree->Print();

    TupleFile->Write();
    TupleFile->Close();


    TFile * fileCA = new TFile("ChargeAsymmetryResults_Skimmed_TTbarSignalMadgraph_LeptonSelEffNegLeptonWithMinus_btag.root","RECREATE");
    //  fileCA->cd();

    // GEN
    histoGenTopRapidity1->Write();
    histoGenTopRapidity2->Write();
    histoGenTopMass1->Write();
    histoGenTopMass2->Write();
    histoGenTopMass1VsTopMass2->Write();
    histoGenDelta_y->Write();
    histoGenTTRapidity->Write();
    histoGenTTPt->Write();
    histoGenTTMass->Write();
    histoGenDelta_yVsTTRapidity->Write();
    histoGenDelta_yVsTTPt->Write();
    histoGenDelta_yVsTTMass->Write();
    histoGenN_plusTTRapidity->Write();
    histoGenN_plusTTPt->Write();
    histoGenN_plusTTMass->Write();
    histoGenN_minusTTRapidity->Write();
    histoGenN_minusTTPt->Write();
    histoGenN_minusTTMass->Write();
    histoGenN_plusMinusN_minusTTRapidity->Write();
    histoGenN_plusPlusN_minusTTRapidity->Write();
    histoGenN_plusMinusN_minusTTPt->Write();
    histoGenN_plusPlusN_minusTTPt->Write();
    histoGenN_plusMinusN_minusTTMass->Write();
    histoGenN_plusPlusN_minusTTMass->Write();
    histoGenA_cTTRapidity->Write();
    histoGenA_cTTPt->Write();
    histoGenA_cTTMass->Write();
    histoFineBinning_GenDelta_yVsTTRapidity->Write();
    histoFineBinning_GenDelta_yVsTTPt->Write();
    histoFineBinning_GenDelta_yVsTTMass->Write();
    histoFineBinning_GenN_plusTTRapidity->Write();
    histoFineBinning_GenN_plusTTPt->Write();
    histoFineBinning_GenN_plusTTMass->Write();
    histoFineBinning_GenN_minusTTRapidity->Write();
    histoFineBinning_GenN_minusTTPt->Write();
    histoFineBinning_GenN_minusTTMass->Write();
    histoFineBinning_GenN_plusMinusN_minusTTRapidity->Write();
    histoFineBinning_GenN_plusPlusN_minusTTRapidity->Write();
    histoFineBinning_GenN_plusMinusN_minusTTPt->Write();
    histoFineBinning_GenN_plusPlusN_minusTTPt->Write();
    histoFineBinning_GenN_plusMinusN_minusTTMass->Write();
    histoFineBinning_GenN_plusPlusN_minusTTMass->Write();
    histoFineBinning_GenA_cTTRapidity->Write();
    histoFineBinning_GenA_cTTPt->Write();
    histoFineBinning_GenA_cTTMass->Write(); 



    // RECO
    histoRecoTopRapidity1->Write();
    histoRecoTopRapidity2->Write();
    histoRecoLeptonRapidity1->Write();
    histoRecoLeptonRapidity2->Write();
    histoRecoTopMass1->Write();
    histoRecoTopMass2->Write();
    histoRecoTopMass1VsTopMass2->Write();
    histoRecoDelta_y->Write();
    histoRecoTTRapidity->Write();
    histoRecoTTPt->Write();
    histoRecoTTMass->Write();
    histoRecoDelta_yVsTTRapidity->Write();
    histoRecoDelta_yVsTTPt->Write();
    histoRecoDelta_yVsTTMass->Write();
    histoRecoN_plusTTRapidity->Write();
    histoRecoN_plusTTPt->Write();
    histoRecoN_plusTTMass->Write();
    histoRecoN_minusTTRapidity->Write();
    histoRecoN_minusTTPt->Write();
    histoRecoN_minusTTMass->Write();
    histoRecoN_plusMinusN_minusTTRapidity->Write();
    histoRecoN_plusPlusN_minusTTRapidity->Write();
    histoRecoN_plusMinusN_minusTTPt->Write();
    histoRecoN_plusPlusN_minusTTPt->Write();
    histoRecoN_plusMinusN_minusTTMass->Write();
    histoRecoN_plusPlusN_minusTTMass->Write();
    histoRecoA_cTTRapidity->Write();
    histoRecoA_cTTPt->Write();
    histoRecoA_cTTMass->Write();
    histoFineBinning_RecoDelta_yVsTTRapidity->Write();
    histoFineBinning_RecoDelta_yVsTTPt->Write();
    histoFineBinning_RecoDelta_yVsTTMass->Write();
    histoFineBinning_RecoN_plusTTRapidity->Write();
    histoFineBinning_RecoN_plusTTPt->Write();
    histoFineBinning_RecoN_plusTTMass->Write();
    histoFineBinning_RecoN_minusTTRapidity->Write();
    histoFineBinning_RecoN_minusTTPt->Write();
    histoFineBinning_RecoN_minusTTMass->Write();
    histoFineBinning_RecoN_plusMinusN_minusTTRapidity->Write();
    histoFineBinning_RecoN_plusPlusN_minusTTRapidity->Write();
    histoFineBinning_RecoN_plusMinusN_minusTTPt->Write();
    histoFineBinning_RecoN_plusPlusN_minusTTPt->Write();
    histoFineBinning_RecoN_plusMinusN_minusTTMass->Write();
    histoFineBinning_RecoN_plusPlusN_minusTTMass->Write();
    histoFineBinning_RecoA_cTTRapidity->Write();
    histoFineBinning_RecoA_cTTPt->Write();
    histoFineBinning_RecoA_cTTMass->Write(); 

    // RECO vs GEN
    histoRecoVsGenTopRapidity1->Write();
    histoRecoVsGenTopRapidity2->Write();
    histoRecoMinusGenDivGenLeptonRapidity1->Write();
    histoRecoMinusGenDivGenLeptonRapidity2->Write();
    histoRecoMinusGenDivGenTopRapidity1->Write();
    histoRecoMinusGenDivGenTopRapidity2->Write();
    histoRecoVsGenTopMass1->Write();
    histoRecoVsGenTopMass2->Write();
    histoRecoMinusGenDivGenTopMass1->Write();
    histoRecoMinusGenDivGenTopMass2->Write();
    histoRecoVsGenDelta_y->Write();
    histoFineBinning_RecoVsGenDelta_y->Write();
    histoRecoMinusGenDivGenDelta_y->Write();
    histoRecoVsGenTTRapidity->Write();
    histoRecoMinusGenDivGenTTRapidity->Write();
    histoRecoVsGenTTPt->Write();
    histoRecoMinusGenDivGenTTPt->Write();
    histoRecoVsGenTTMass->Write();
    histoRecoMinusGenDivGenTTMass->Write();
    histoDelta_yEfficiencyN->Write();
    histoDelta_yEfficiencyD->Write();
    histoDelta_yEfficiency->Write();
    histoDelta_yVsTTRapidityEfficiency->Write();
    histoDelta_yVsTTPtEfficiency->Write();
    histoDelta_yVsTTMassEfficiency->Write();
    histoFineBinning_Delta_yEfficiencyN->Write();
    histoFineBinning_Delta_yEfficiencyD->Write();
    histoFineBinning_Delta_yEfficiency->Write();
    histoFineBinning_Delta_yVsTTRapidityEfficiency->Write();
    histoFineBinning_Delta_yVsTTPtEfficiency->Write();
    histoFineBinning_Delta_yVsTTMassEfficiency->Write();


    //    fileCA->Write();
    fileCA->Close();
    delete fileCA;

    cout << "num_mttbar_eff = " <<  num_mttbar_eff << endl;
    cout << "den_mttbar_eff = " <<  den_mttbar_eff << endl;
    cout << "mttbar_eff = " <<  num_mttbar_eff / den_mttbar_eff << endl;

  return (0);
}
示例#21
0
void plotsAfterCuts_NoLegs() {

    gStyle->SetOptStat();
    gROOT->SetStyle("Plain");
    using namespace std;

    //  #include <exception>;

    //    TFile *file = TFile::Open("rfio:/castor/cern.ch/user/d/degrutto/incl15WithBsPv/NtupleLoose_test_inclu15_1_2.root");
    // TFile *file = TFile::Open("../NutpleLooseTestNew_oneshot_all_10_1.root");
//TFile *file = TFile::Open("rfio:/castor/cern.ch/user/d/degrutto/zmmWithBsPv/NtupleLoose_test.root");
//    TTree * Events = dynamic_cast< TTree *> (file->Get("Events"));

    TChain Events("Events");
    //     Events.Add("../../NtupleLoose_135_all.root")
    Events.Add("/scratch2/users/degruttola/data/OfficialJSON/blessed/NtupleLoose_132440_139790.root");
    Events.Add("/scratch2/users/degruttola/data/OfficialJSON/blessed/NtupleLoose_139791-140159_v2.root");
    Events.Add("/scratch2/users/degruttola/data/OfficialJSON/blessed/NtupleLoose_140160-140182.root");
    Events.Add("/scratch2/users/degruttola/data/OfficialJSON/blessed/NtupleLoose_140183-140399.root");
    Events.Add("/scratch2/users/degruttola/data/OfficialJSON/blessed/NtupleLoose_140440-141961.root");
    Events.Add("../NtupleLoose_142035-142664.root");
    Events.Add("../NtupleLoose_142665-143179.root");
    Events.Add("../NtupleLoose_143180-143336.root");
    Events.Add("../NtupleLoose_143337-144114.root");
    Events.Add("../NtupleLoose_144114_v2.root");



    TFile * output_file = TFile::Open("histo_3p07_noCuts_eta2p1.root", "RECREATE");
    // TFile * output_file = TFile::Open("histo_test.root", "RECREATE");

    // zGolden plots
    TCut cut_zGolden("zGoldenMass>0 && zGoldenMass<200 && zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && zGoldenDau1Iso03SumPt< 3.0 && zGoldenDau2Iso03SumPt < 3.0 && abs(zGoldenDau1Eta)<2.4 &&  abs(zGoldenDau2Eta)<2.4 && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 && (zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && (zGoldenDau1HLTBit==1 || zGoldenDau2HLTBit==1) ");
    TDirectory * dir = output_file->mkdir("goodZToMuMuPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    //  Events.Draw("zGoldenMass");
    Events.Project("zMass", "zGoldenMass", cut_zGolden );
    cout<<"Number of zGoldenAA : "<<zMass->Integral(60,120)<<endl;
    setGraphics(zMass);
    zMass->Write();
    delete zMass;


    TCut cut_zGoldenPt15("zGoldenMass>0 && zGoldenDau1Pt> 15 && zGoldenDau2Pt>15 && zGoldenDau1Iso03SumPt< 3.0 && zGoldenDau2Iso03SumPt < 3.0  &&  abs(zGoldenDau1Eta)<2.1 &&  abs(zGoldenDau2Eta)<2.1 && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 &&(zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && (zGoldenDau1HLTBit==1 || zGoldenDau2HLTBit==1)");
    dir->cd();

    TH1F * zMassPt15 = new TH1F("zMassPt15", "zMassPt15", 200, 0, 200);
    Events.Project("zMassPt15", "zGoldenMass", cut_zGoldenPt15  );
    setGraphics(zMassPt15);
    cout<<"Number of zGoldenPt15 : "<<zMassPt15->Integral(60,120)<<endl;
    zMassPt15->Write();
    delete zMassPt15;



    output_file->cd("/");

    TCut cut2_zGolden1HLT("zGoldenMass>0 && zGoldenMass<200 && zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && zGoldenDau1Iso03SumPt< 3.0 && zGoldenDau2Iso03SumPt < 3.0 && abs(zGoldenDau1Eta)<2.1 &&  abs(zGoldenDau2Eta)<2.1 && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 &&(zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && ( zGoldenDau1HLTBit ==0 || zGoldenDau2HLTBit ==0)");
    TDirectory * dir = output_file->mkdir("goodZToMuMu1HLTPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zGoldenMass", cut2_zGolden1HLT );
    cout<<"Number of zGolden1HLT : "<<zMass->Integral(60,120)<<endl;
    zMass->Write();
    delete zMass;
//zMass2->Write();

    output_file->cd("/");


    output_file->cd("/");

    TCut cut2_zGoldenAB1HLT("zGoldenMass>0 && zGoldenMass<200 && zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && zGoldenDau1Iso03SumPt< 3.0 && zGoldenDau2Iso03SumPt < 3.0 && (( abs(zGoldenDau1Eta)>2.1 || abs(zGoldenDau2Eta)>2.1 ) )  && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 &&(zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && ( zGoldenDau1HLTBit==1 || zGoldenDau2HLTBit ==1)");
    TDirectory * dir = output_file->mkdir("goodZToMuMuAB1HLTPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zGoldenMass", cut2_zGoldenAB1HLT );
    cout<<"Number of zGoldenAB1HLT : "<<zMass->Integral(60,120)<<endl;
    zMass->Write();
    delete zMass;
//zMass2->Write();

    output_file->cd("/");



    TCut cut2_zGoldenBB1HLT("zGoldenMass>0 && zGoldenMass<200 && zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && zGoldenDau1Iso03SumPt< 3.0 && zGoldenDau2Iso03SumPt < 3.0 && (( abs(zGoldenDau1Eta)>2.1 && abs(zGoldenDau2Eta)>2.1 ) )  && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 &&(zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && ( zGoldenDau1HLTBit==1 || zGoldenDau2HLTBit ==1)");
    TDirectory * dir = output_file->mkdir("goodZToMuMuBB1HLTPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zGoldenMass", cut2_zGoldenBB1HLT );
    cout<<"Number of zGoldenBB1HLT : "<<zMass->Integral(60,120)<<endl;
    zMass->Write();
    delete zMass;
//zMass2->Write();

    output_file->cd("/");



    TCut cut2_zGolden2HLT("zGoldenMass>0 && zGoldenMass<200 && zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && zGoldenDau1Iso03SumPt< 3.0 && zGoldenDau2Iso03SumPt < 3.0 && abs(zGoldenDau1Eta)<2.1 &&  abs(zGoldenDau2Eta)<2.1 && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 &&(zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && ( zGoldenDau1HLTBit ==1 && zGoldenDau2HLTBit ==1)");

    TDirectory * dir = output_file->mkdir("goodZToMuMu2HLTPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zGoldenMass", cut2_zGolden2HLT );
    zMass->Write();
    cout<<"Number of zGolden2HLT : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");


// zGoldenOneNotIso plots
    TCut cut_zGoldenOneNotIso("zGoldenMass>0 && zGoldenMass<200 && zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && ( (zGoldenDau1Iso03SumPt> 3.0 &&  zGoldenDau2Iso03SumPt < 3.0) || (zGoldenDau2Iso03SumPt> 3.0 &&  zGoldenDau1Iso03SumPt < 3.0))  && abs(zGoldenDau1Eta)<2.1 &&  abs(zGoldenDau2Eta)<2.1 && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 &&(zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && ( zGoldenDau1HLTBit ==1 || zGoldenDau2HLTBit ==1)");
    TDirectory * dir = output_file->mkdir("oneNonIsolatedZToMuMuPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zGoldenMass", cut_zGoldenOneNotIso );
    zMass->Write();
    cout<<"Number of zGoldenOneNotIso : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");

//  // zGoldenTwoNotIso plots
    TCut cut_zGoldenTwoNotIso("zGoldenMass>0 && zGoldenMass<200 && zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && (zGoldenDau1Iso03SumPt> 3.0 &&  zGoldenDau2Iso03SumPt > 3.0) && abs(zGoldenDau1Eta)<2.1 &&  abs(zGoldenDau2Eta)<2.1 && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 &&(zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && ( zGoldenDau1HLTBit ==1 || zGoldenDau2HLTBit ==1)");
    TDirectory * dir = output_file->mkdir("twoNonIsolatedZToMuMuPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass","zGoldenMass", cut_zGoldenTwoNotIso );
    zMass->Write();
    cout<<"Number of zGoldenTwoNotIso : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");

// zGoldenNotIso plots
    TCut cut_zGoldenNotIso("zGoldenMass>0 && zGoldenMass<200 && zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && (zGoldenDau1Iso03SumPt> 3.0 ||  zGoldenDau2Iso03SumPt > 3.0) && abs(zGoldenDau1Eta)<2.1 &&  abs(zGoldenDau2Eta)<2.1 && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && abs(zGoldenDau1dxyFromBS)<0.2 && abs(zGoldenDau2dxyFromBS)<0.2 &&(zGoldenDau1NofStripHits + zGoldenDau1NofPixelHits)>=0 && (zGoldenDau2NofStripHits + zGoldenDau2NofPixelHits)>=0 && zGoldenDau1NofMuonHits>=0 && zGoldenDau2NofMuonHits>=0 && ( zGoldenDau1HLTBit ==1 || zGoldenDau2HLTBit ==1)");
    TDirectory * dir = output_file->mkdir("nonIsolatedZToMuMuPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zGoldenMass", cut_zGoldenNotIso );
    zMass->Write() ;
    cout<<"Number of zGoldenNotIso : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");

    // zGoldenSameCharge plots........
    TCut cut_zSameCharge("zSameChargeMass>0 && zSameChargeMass<200 && zSameChargeDau1Pt> 20 && zSameChargeDau2Pt>20 && zSameChargeDau1Iso03SumPt< 3.0 && zSameChargeDau1Iso03SumPt < 3.0 && abs(zSameChargeDau1Eta)<2.1 &&  abs(zSameChargeDau2Eta)<2.1 && zSameChargeDau1Chi2<1000 && zSameChargeDau2Chi2<1000 && abs(zSameChargeDau1dxyFromBS)<0.2 && abs(zSameChargeDau2dxyFromBS)<0.2 &&(zSameChargeDau1NofStripHits + zSameChargeDau1NofPixelHits)>=0 && (zSameChargeDau2NofStripHits + zSameChargeDau2NofPixelHits)>=0 && zSameChargeDau1NofMuonHits>=0 && zSameChargeDau2NofMuonHits>=0 && (zSameChargeDau1HLTBit==1 || zSameChargeDau2HLTBit==1) ");
    TDirectory * dir = output_file->mkdir("goodZToMuMuSameChargePlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zSameChargeMass", cut_zSameCharge );
    zMass->Write();
    cout<<"Number of zGoldenSameCharge : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");

// zGoldenSameChargeNotIso plots........
    TCut cut_zSameChargeNotIso("zSameChargeMass>0 && zSameChargeMass<200 && zSameChargeDau1Pt> 20 && zSameChargeDau2Pt>20 && ( zSameChargeDau1Iso03SumPt> 3.0 || zSameChargeDau1Iso03SumPt > 3.0) && abs(zSameChargeDau1Eta)<2.1 &&  abs(zSameChargeDau2Eta)<2.1 && zSameChargeDau1Chi2<1000 && zSameChargeDau2Chi2<1000 && abs(zSameChargeDau1dxyFromBS)<0.2 && abs(zSameChargeDau2dxyFromBS)<0.2 &&(zSameChargeDau1NofStripHits + zSameChargeDau1NofPixelHits)>=0 && (zSameChargeDau2NofStripHits + zSameChargeDau2NofPixelHits)>=0 && zSameChargeDau1NofMuonHits>=0 && zSameChargeDau2NofMuonHits>=0 && (zSameChargeDau1HLTBit==1 || zSameChargeDau2HLTBit==1) ");
    TDirectory * dir = output_file->mkdir("goodZToMuMuSameChargeNotIsoPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zSameChargeMass", cut_zSameChargeNotIso );
    zMass->Write();
    cout<<"Number of zGoldenSameChargeNotIso : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");


// zMuTrk plots
    TCut cut_zMuTrk("zMuTrkMass>0 && zMuTrkMass<200 && zMuTrkDau1Pt> 20 && zMuTrkDau2Pt>20 && zMuTrkDau1Iso03SumPt< 3.0 && zMuTrkDau2Iso03SumPt < 3.0 && abs(zMuTrkDau1Eta)<2.1 &&  abs(zMuTrkDau2Eta)<2.1 && zMuTrkDau1Chi2<1000 && zMuTrkDau2TrkChi2<1000 && abs(zMuTrkDau1dxyFromBS)<0.2 && abs(zMuTrkDau2dxyFromBS)<.2 &&(zMuTrkDau1TrkNofStripHits + zMuTrkDau1TrkNofPixelHits)>=0 && (zMuTrkDau2TrkNofStripHits + zMuTrkDau2TrkNofPixelHits)>=0 && zMuTrkDau1NofMuonHits>=0  && (zMuTrkDau1HLTBit==1) ");
    TDirectory * dir = output_file->mkdir("goodZToMuMuOneTrackPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zMuTrkMass", cut_zMuTrk );
    zMass->Write();
    cout<<"Number of zMuTrk : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");

// zMuTrkMu plots
    TCut cut_zMuTrkMu("zMuTrkMuMass>0 && zMuTrkMuMass<200 && zMuTrkMuDau1Pt> 20 && zMuTrkMuDau2Pt>20 && zMuTrkMuDau1Iso03SumPt< 3.0 && zMuTrkMuDau2Iso03SumPt < 3.0 && abs(zMuTrkMuDau1Eta)<2.1  && abs(zMuTrkMuDau1dxyFromBS)<0.2 && abs(zMuTrkMuDau2dxyFromBS)<0.2  && abs(zMuTrkMuDau2Eta)<2.1  && ( (zMuTrkMuDau1HLTBit==1  && zMuTrkMuDau1GlobalMuonBit ==1 ) || ( zMuTrkMuDau2HLTBit==1  && zMuTrkMuDau2GlobalMuonBit ==1))");// zMuTrkMuDau1Chi2<1000 && zMuTrkMuDau2Chi2<1000 && abs(zMuTrkMuDau1dxyFromBS)<0.2 && abs(zMuTrkMuDau2dxyFromBS)<0.2 &&(zMuTrkMuDau1NofStripHits + zMuTrkMuDau1NofPixelHits)>=0 && (zMuTrkMuDau2NofStripHits + zMuTrkMuDau2NofPixelHits)>=0 && zMuTrkMuDau1NofMuonHits>=-1 && zMuTrkMuDau2NofMuonHits>=-1  ");
    TDirectory * dir = output_file->mkdir("goodZToMuMuOneTrackerMuonPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zMuTrkMuMass", cut_zMuTrkMu );
    zMass->Write();
    cout<<"Number of zMuTrkMu : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");



    // zMuSta plots
    TCut cut_zMuSta("zMuStaMass>0 && zMuStaMass<200 && zMuStaDau1Pt> 20 && zMuStaDau2Pt>20 && zMuStaDau1Iso03SumPt< 3.0 && zMuStaDau2Iso03SumPt < 3.0 && abs(zMuStaDau1Eta)<2.1 &&  abs(zMuStaDau2Eta)<2.1 && ((zMuStaDau1HLTBit==1  && zMuStaDau1GlobalMuonBit ==1 && abs(zMuStaDau1dxyFromBS)<0.2 ) || ( zMuStaDau2HLTBit==1  && zMuStaDau2GlobalMuonBit ==1 && abs(zMuStaDau2dxyFromBS)<0.2) )");// zMuStaDau1Chi2<1000 && zMuStaDau2Chi2<1000 && abs(zMuStaDau1dxyFromBS)<0.2 && abs(zMuStaDau2dxyFromBS)<0.2 &&(zMuStaDau1NofStripHits + zMuStaDau1NofPixelHits)>=0 && (zMuStaDau2NofStripHits + zMuStaDau2NofPixelHits)>=0 && zMuStaDau1NofMuonHits>=-1 && zMuStaDau2NofMuonHits>=-1 &&  ");
    TDirectory * dir = output_file->mkdir("goodZToMuMuOneStandAloneMuonPlots");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zMuStaMass", cut_zMuSta );
    zMass->Write();
    cout<<"Number of zMuSta : "<<zMass->Integral(60,120)<<endl;
    delete zMass;
    output_file->cd("/");

// zMuSta plots
    TCut cut_zMuMuSta("zGoldenDau1Pt> 20 && zGoldenDau2Pt>20 && zGoldenDau1Iso03SumPt< 3.0 && zGoldenDau1Iso03SumPt < 3.0  && abs(zGoldenDau1Eta)<2.1 &&  abs(zGoldenDau2Eta)<2.1 && zGoldenDau1Chi2<1000 && zGoldenDau2Chi2<1000 && zGoldenDau1dxyFromBS<0.02 && zGoldenDau2dxyFromBS<0.02");
    TDirectory * dir = output_file->mkdir("zmumuSaMassHistogram");
    dir->cd();
    TH1F * zMass = new TH1F("zMass", "zMass", 200, 0, 200);
    Events.Project("zMass", "zGoldenMassSa", cut_zMuMuSta );
    zMass->Write();
    delete zMass;
    output_file->cd("/");

    /*
    TDirectory * dir = output_file->mkdir("zPlots");
    dir->cd();
    TH1F * zGoldenPt = new TH1F("zGoldenPt", "zGoldenPt", 200, 0, 200);
    Events.Project("zGoldenPt", "zGoldenPt", cut_zGolden );
    zGoldenPt->Write();
    delete zGoldenPt;


    TH1F * zGoldenY = new TH1F("zGoldenY", "zGoldenY", 200, -5, 5);
    Events.Project("zGoldenY", "zGoldenY", cut_zGolden );
    zGoldenY->Write();
    delete zGoldenY;

    output_file->cd("/");



    TDirectory * dir = output_file->mkdir("MuPlots");
    dir->cd();


    TH1F * muNotTriggeredEta = new TH1F("muNotTriggeredEta", "muNotTriggeredEta", 240, -6, 6.);
    TH1F * h2 = new TH1F("h2", "h2", 240, -6, 6.);

    Events.Project("muNotTriggeredEta","zGoldenDau1Eta", "zGoldenDau1HLTBit==0");
    Events.Project("h2","zGoldenDau2Eta", "zGoldenDau2HLTBit==0");

    muNotTriggeredEta->Add(h2);
    muNotTriggeredEta->Write();
    delete muNotTriggeredEta;
    delete h2;

    TH1F * zGoldenDauHighPt = new TH1F("zGoldenDauHighPt", "zGoldenDauHighPt", 200, 0, 200);
    Events.Project("zGoldenDauHighPt", "max(zGoldenDau1Pt, zGoldenDau2Pt)", cut_zGolden );
    zGoldenDauHighPt->Write();
    delete zGoldenDauHighPt;

    TH1F * zGoldenDauLowPt = new TH1F("zGoldenDauLowPt", "zGoldenDauLowPt", 200, 0, 200);
    Events.Project("zGoldenDauLowPt", "min(zGoldenDau1Pt, zGoldenDau2Pt)", cut_zGolden );
    zGoldenDauLowPt->Write();
    delete zGoldenDauLowPt;

    //(mu1.phi -mu2.phi)
    TH1F * deltaPhi = new TH1F("deltaPhi", "deltaPhi", 120, 0, 6.);
    TH1F * h2 = new TH1F("h2", "h2", 120, 0, 6. );
    TH1F * h3 = new TH1F("h3", "h3", 120, 0, 6. );
    */

    /*    result = phi1 - phi2;
    040     while (result > M_PI) result -= 2*M_PI;
    041     while (result <= -M_PI) result += 2*M_PI;
    042     return result;
    */
    /*
    Events.Project("deltaPhi", "abs(zGoldenDau1Phi - zGoldenDau2Phi)", "-TMath::Pi() < (zGoldenDau1Phi - zGoldenDau2Phi) < TMath::Pi()" , "zGoldenDau1Pt>20 && zGoldenDau2Pt >20"  + cut_zGolden);
    Events.Project("h2", "abs(zGoldenDau1Phi - zGoldenDau2Phi - 2 * TMath::Pi())", "(zGoldenDau1Phi - zGoldenDau2Phi) > TMath::Pi()" , "zGoldenDau1Pt>20 && zGoldenDau2Pt >20" + + cut_zGolden);
    Events.Project("h3", "abs(zGoldenDau1Phi - zGoldenDau2Phi + 2 * TMath::Pi())", "(zGoldenDau1Phi - zGoldenDau2Phi) <=  -TMath::Pi()", "zGoldenDau1Pt>20 && zGoldenDau2Pt >20" + cut_zGolden );

    deltaPhi->Add(h2, h3);
    deltaPhi->Write();
    delete deltaPhi;;
    delete h2;
    delete h3;



    // mu1.eta -mu2.eta
    TH1F * deltaEta = new TH1F("deltaEta", "deltaEta", 120, 0, 6.);
    Events.Project("deltaEta", "abs(zGoldenDau1Eta - zGoldenDau2Eta)", cut_zGolden );
    deltaEta->Write();
    delete deltaEta;

    TH1F * dua1Phi = new TH1F("dau1Phi", "dau1Phi", 120, -6, 6.);
    Events.Project("dau1Phi", "zGoldenDau1Phi" , cut_zGolden);
    dau1Phi->Write();
    delete dau1Phi;

    TH1F * dua2Phi = new TH1F("dau2Phi", "dau2Phi", 120, -6, 6.);
    Events.Project("dau2Phi", "zGoldenDau2Phi" , cut_zGolden);
    dau2Phi->Write();
    delete dau2Phi;

    TH1F * dau1Eta = new TH1F("dua1Eta", "dau1Eta", 120, -6, 6.);
    Events.Project("dau1Eta", "zGoldenDau1Eta", cut_zGolden );
    dau1Eta->Write();
    delete dau1Eta;

    TH1F * dau2Eta = new TH1F("dua2Eta", "dau2Eta", 120, -6, 6.);
    Events.Project("dau2Eta", "zGoldenDau2Eta" , cut_zGolden);
    dau2Eta->Write();
    delete dau2Eta;

    // quality variables
    // caveat: I'm  requiring isolations
    TH1F * dau1Chi2 = new TH1F("dua1Chi2", "dau1Chi2", 1000, 0, 100);
    Events.Project("dua1Chi2", "zGoldenDau1Chi2", cut_zGolden );
    dau1Chi2->Write();
    delete dau1Chi2;

    TH1F * dau2Chi2 = new TH1F("dua2Chi2", "dau2Chi2", 1000, 0, 100);
    Events.Project("dau2Chi2", "zGoldenDau2Chi2", cut_zGolden );
    dau2Chi2->Write();
    delete dau2Chi2;


    TH1F * dau1Dxy = new TH1F("dua1Dxy", "dau1Dxy", 500, 0, 5);
    Events.Project("dua1Dxy", "zGoldenDau1dxyFromBS", cut_zGolden );
    dau1Dxy->Write();
    delete dau1Dxy;

    TH1F * dau2Dxy = new TH1F("dua2Dxy", "dau2Dxy", 500, 0, 5);
    Events.Project("dua2Dxy", "zGoldenDau2dxyFromBS", cut_zGolden );
    dau2Dxy->Write();
    delete dau2Dxy;


    TH1F * dau1Dz= new TH1F("dua1Dz", "dau1Dz", 500, 0, 20);
    Events.Project("dua1Dz", "zGoldenDau1dzFromBS", cut_zGolden );
    dau1Dz->Write();
    delete dau1Dz;

    TH1F * dau2Dz = new TH1F("dua2Dz", "dau2Dz", 500, 0, 20);
    Events.Project("dua2Dz", "zGoldenDau2dzFromBS", cut_zGolden);
    dau2Dz->Write();
    delete dau2Dz;
    */
    /*
    TH1F * dau1NofHit = new TH1F("dua1NofHit", "dau1NofHit", 100, -0.5, 99.5);
    Events.Project("dua1NofHit", "zGoldenDau1NofHit", cut_zGolden );
    dau1NofHit->Write();
    delete dau1NofHit;

    TH1F * dau2NofHit = new TH1F("dua2NofHit", "dau2NofHit", 100, -0.5, 99.5);
    Events.Project("dua2NofHit", "zGoldenDau2NofHit", cut_zGolden );
    dau2NofHit->Write();
    delete dau2NofHit;
    */
    /*
    TH1F * dau1NofMuCh = new TH1F("dua1NofMuCh", "dau1NofMuCh", 20, -0.5, 19.5);
    Events.Project("dua1NofMuCh", "zGoldenDau1NofMuChambers", cut_zGolden );
    dau1NofMuCh->Write();
    delete dau1NofMuCh;

    TH1F * dau2NofMuCh = new TH1F("dua2NofMuCh", "dau2NofMuCh", 20, -0.5, 19.5);
    Events.Project("dua2NofMuCh", "zGoldenDau2NofMuChambers", cut_zGolden );
    dau2NofMuCh->Write();
    delete dau2NofMuCh;


    TH1F * dau1NofMuMatches = new TH1F("dua1NofMuMatches", "dau1NofMuMatches", 20, -0.5, 19.5);
    Events.Project("dua1NofMuMatches", "zGoldenDau1NofMuMatches", cut_zGolden );
    dau1NofMuMatches->Write();
    delete dau1NofMuMatches;

    TH1F * dau2NofMuMatches = new TH1F("dua2NofMuMatches", "dau2NofMuMatches", 20, -0.5, 19.5);
    Events.Project("dua2NofMuMatches", "zGoldenDau2NofMuMatches", cut_zGolden );
    dau2NofMuMatches->Write();
    delete dau2NofMuMatches;

    TH1F * dau1EmEnergy  = new TH1F("dua1EmEnergy", "dau1EmEnergy", 200, -0.1, 19.9);
    Events.Project("dua1EmEnergy", "zGoldenDau1MuEnergyEm", cut_zGolden );
    dau1EmEnergy->Write();
    delete dau1EmEnergy;

    TH1F * dau2EmEnergy  = new TH1F("dua2EmEnergy", "dau2EmEnergy", 200, -0.1, 19.9);
    Events.Project("dua2EmEnergy", "zGoldenDau2MuEnergyEm", cut_zGolden );
    dau2EmEnergy->Write();
    delete dau2EmEnergy;

    TH1F * dau1HadEnergy  = new TH1F("dua1HadEnergy", "dau1HadEnergy", 200, -0.1, 19.9);
    Events.Project("dua1HadEnergy", "zGoldenDau1MuEnergyHad", cut_zGolden );
    dau1HadEnergy->Write();
    delete dau1HadEnergy;

    TH1F * dau2HadEnergy  = new TH1F("dua2HadEnergy", "dau2HadEnergy", 200, -0.1, 19.9);
    Events.Project("dua2HadEnergy", "zGoldenDau2MuEnergyHad", cut_zGolden );
    dau2HadEnergy->Write();
    delete dau2HadEnergy;




    TH2F * MuChambersVsMuMatches = new TH2F("MuChambersVsMuMatches", "MuChambersVsMuMatches", 21, -0.5, 20.5, 21, -0.5, 20.5);
    TH2F * hh2= new TH2F("hh2", "hh2", 21, -0.5, 20.5, 21, -0.5, 20.5);
    Events.Project("MuChambersVsMuMatches", "zGoldenDau1NofMuChambers:zGoldenDau1NofMuMatches", cut_zGolden);
    Events.Project("hh2", "zGoldenDau2NofMuChambers:zGoldenDau2NofMuMatches", cut_zGolden);

    MuChambersVsMuMatches->Add(hh2);
    MuChambersVsMuMatches->Write();
    MuChambersVsMuMatches->SetDrawOption("Box");
    //  MuChambersVsMuMatches->Draw("BOX");
    delete MuChambersVsMuMatches;
    delete hh2;
    output_file->cd("/");

    TDirectory * dir = output_file->mkdir("TrkPlots");
    dir->cd();

    */

    /*  TH1F * nofHitTrk = new TH1F("nofHitTrk", "nofHitTrk", 100, -0.5, 99.5);
    Events.Project("nofHitTrk", "zMuTrkDau2NofHitTk", cut_zMuTrk );
    nofHitTrk->Write();
    delete nofHitTrk;
    */
    /*
    TH1F * trkChi2 = new TH1F("trkChi2", "trkChi2", 100, -0.5, 99.5);
    Events.Project("trkChi2", "zMuTrkDau2Chi2", cut_zMuTrk );
    trkChi2->Write();
    delete trkChi2;


    output_file->cd("/");



    TDirectory * dir = output_file->mkdir("StaPlots");
    dir->cd();

    // sta as zDaudxyFromBS=-1 by construction....

    TH1F *  staNofMuCh = new TH1F("staNofMuCh", "staNofMuCh", 20, -0.5, 19.5);
    TH1F * h2 = new TH1F("h2", "h2", 20, -0.5, 19.5);
    Events.Project("staNofMuCh", "zMuStaDau1NofMuChambers", cut_zMuSta + "zMuStaDau1dxyFromBS==-1" );
    Events.Project("h2", "zMuStaDau2NofMuChambers", cut_zMuSta + "zMuStaDau2dxyFromBS==-1" );
    staNofMuCh->Add(h2);
    staNofMuCh->Write();
    delete staNofMuCh;
    delete h2;

    TH1F *  staNofMuMatches = new TH1F("staNofMuMatches", "staNofMuMatches", 20, -0.5, 19.5);
    TH1F * h2 = new TH1F("h2", "h2", 20, -0.5, 19.5);
    Events.Project("staNofMuMatches", "zMuStaDau1NofMuMatches", cut_zMuSta + "zMuStaDau1dxyFromBS==-1" );
    Events.Project("h2", "zMuStaDau2NofMuMatches", cut_zMuSta + "zMuStaDau2dxyFromBS==-1" );
    staNofMuMatches->Add(h2);
    staNofMuMatches->Write();
    delete staNofMuMatches;
    delete h2;

    TH2F * MuChambersVsMuMatches= new TH2F("MuChambersVsMuMatches", "MuChambersVsMuMatches", 21, -0.5, 20.5, 21, -0.5, 20.5);
    TH2F * hh2= new TH2F("hh2", "hh2", 21, -0.5, 20.5, 21, -0.5, 20.5);
    Events.Project("MuChambersVsMuMatches", "zMuStaDau1NofMuChambers:zMuStaDau1NofMuMatches", cut_zMuSta);
    Events.Project("hh2", "zMuStaDau2NofMuChambers:zMuStaDau2NofMuMatches", cut_zMuSta);
    MuChambersVsMuMatches->Add(hh2);
    MuChambersVsMuMatches->SetDrawOption("Box");
    MuChambersVsMuMatches->Write();
    delete MuChambersVsMuMatches;
    delete hh2;
    output_file->cd("/");

    // isolations...
     TDirectory * dir = output_file->mkdir("IsoPlots");
     dir->cd();


     TH1F * TrkIsoPt20= new TH1F("TrkIsoPt20", "TrkIsoPt20", 200, 0, 20);
     TH1F * h2 = new TH1F("h2", "h2", 200, 0, 20);
     Events.Project("TkIsoPt20", "zGoldenDau1TrkIso" , "zGoldenDau2Pt>20");
     Events.Project("h2", "zGoldenDau2TrkIso", "zGoldenDau2Pt>20" );
     TrkIsoPt20->Add(h2);
     TrkIsoPt20->Write();
     delete TrkIsoPt20;
     delete h2;

     TH1F * EcalIsoPt20 = new TH1F("EcalIsoPt20", "EcalIsoPt20", 200, 0, 20);
     TH1F * h2 = new TH1F("h2", "h2", 200, 0, 20);
     Events.Project("TkIsoPt20", "zGoldenDau1EcalIso" , "zGoldenDau1Pt>20");
     Events.Project("h2", "zGoldenDau2EcalIso", "zGoldenDau2Pt>20" );
     EcalIsoPt20->Add(h2);
     EcalIsoPt20->Write();
     delete EcalIsoPt20;
     delete h2;

     TH1F * HcalIsoPt20 = new TH1F("HcalIsoPt20", "HcalIsoPt20", 200, 0, 20);
     TH1F * h2 = new TH1F("h2", "h2", 200, 0, 20);
     Events.Project("TkIsoPt20", "zGoldenDau1HcalIso" , "zGoldenDau1Pt>20" );
     Events.Project("h2", "zGoldenDau2HcalIso" , "zGoldenDau2Pt>20");
     HcalIsoPt20->Add(h2);
     HcalIsoPt20->Write();
     delete HcalIsoPt20;
     delete h2;

     TH1F * TrkIsoPt15= new TH1F("TrkIsoPt15", "TrkIsoPt15", 200, 0, 20);
     TH1F * h2 = new TH1F("h2", "h2", 200, 0, 20);
     Events.Project("TkIsoPt15", "zGoldenDau1TrkIso" , "zGoldenDau1Pt>20");
     Events.Project("h2", "zGoldenDau2TrkIso", "zGoldenDau2Pt>15" );
     TrkIsoPt15->Add(h2);
     TrkIsoPt15->Write();
     delete TrkIsoPt15;
     delete h2;

     TH1F * EcalIsoPt15 = new TH1F("EcalIsoPt15", "EcalIsoPt15", 200, 0, 20);
     TH1F * h2 = new TH1F("h2", "h2", 200, 0, 20);
     Events.Project("TkIsoPt15", "zGoldenDau1EcalIso" , "zGoldenDau1Pt>20");
     Events.Project("h2", "zGoldenDau2EcalIso", "zGoldenDau2Pt>15" );
     EcalIsoPt15->Add(h2);

     EcalIsoPt15->Write();
     delete EcalIsoPt15;
     delete h2;

     TH1F * HcalIsoPt15 = new TH1F("HcalIsoPt15", "HcalIsoPt15", 200, 0, 20);
     TH1F * h2 = new TH1F("h2", "h2", 200, 0, 20);
     Events.Project("TkIsoPt15", "zGoldenDau1HcalIso" , "zGoldenDau1Pt>20" );
     Events.Project("h2", "zGoldenDau2HcalIso" , "zGoldenDau2Pt>15");
     HcalIsoPt15->Add(h2);

     HcalIsoPt15->Write();
     delete HcalIsoPt15;
     delete h2;
     output_file->cd("/");

    */

    output_file->Close();


}
void makeStack(TString myVar, TString myCut, TString myName, TString myAxisNameX, TString myAxisNameY, 
               vector<const Sample*>& listOfSignals, vector<const Sample*>& listOfSamples, vector<const Sample*> listOfDatasets, 
               TString inFileName,
               bool isBlind, bool isLog, bool drawSignal, bool drawLegend,
               int nBins, float xLow, float xHigh,
               float* xlowVec)
{
  // prepare the input file
  TFile* infile = new TFile(inFileName, "READ"); 
  infile -> cd();
  
  // prepare the stack
  THStack *hs = new THStack("hs","");
  // prepare the histos pointers
  TH1F*   hist[20];
  // prepare the tree pointers
  TTree*  tree[20];
  // prepare the legend
  TLegend* leg = new TLegend(.7485,.7225,.9597,.9604);
  leg->SetFillColor(0);
  // prepare the colors
  Int_t col[20] = {46,2,12,5,3,4,9,7,47,49,49,50,51,52,53,54,55,56,57,58};
  // prepare the cut
  if (isBlind) myCut += "*(phoMetDeltaPhi < 2.9)";        
  // prepare the Y axis lable
  if (xlowVec != 0) myAxisNameY = "Events/" + myAxisNameY;
  else {
    float binWidth = (xHigh-xLow)/nBins;
    TString tempString;
    tempString.Form("%.2f ",binWidth); 
    myAxisNameY = "Events/" + tempString + myAxisNameY;
  }
  // prepare the legend strings
  vector<TString> theLegends;
  
  // loop through the datasets and produce the plots
  TH1F* hdata;
  TH1F* hsignal;
  //prepare data and signal histos
  if (xlowVec != 0) hdata   = new TH1F("hdata","",nBins,xlowVec);
  else hdata = new TH1F("hdata","",nBins,xLow,xHigh);
  if (xlowVec != 0) hsignal = new TH1F("hsignal","",nBins,xlowVec);
  else hsignal = new TH1F("hsignal","",nBins,xLow,xHigh);

  TTree*  treedata[20];
  for (UInt_t iDatas=0; iDatas < listOfDatasets.size(); iDatas++) {
    //get the tree
    treedata[iDatas] = (TTree*) infile -> Get(listOfDatasets.at(iDatas)->Name()->Data());

    //fill the histogram
    if ( iDatas == 0 ) treedata[iDatas] -> Draw(myVar + " >> hdata","hlt_weight*evt_weight*kf_weight*pu_weight" + myCut);
    else treedata[iDatas] -> Draw(myVar + " >>+ hdata","hlt_weight*evt_weight*kf_weight*pu_weight" + myCut);
    
    if ( isBlind && iDatas == 0 ) leg -> AddEntry(hdata, "DATA (19.8 fb^{-1})", "pl");    
    
  }//end loop on datasets
  if (xlowVec != 0) {
    for (int iBin = 1; iBin <= nBins; iBin++) hdata->SetBinError  (iBin,hdata->GetBinError(iBin)/hdata->GetBinWidth(iBin));
    for (int iBin = 1; iBin <= nBins; iBin++) hdata->SetBinContent(iBin,hdata->GetBinContent(iBin)/hdata->GetBinWidth(iBin));
  }

  TTree*  treesignal[20];
  for (UInt_t iSignal=0; iSignal < listOfSignals.size(); iSignal++) {
    //get the tree
    treesignal[iSignal] = (TTree*) infile -> Get(listOfSignals.at(iSignal)->Name()->Data());

    //fill the histogram
    TString thisScale = Form("%f *", *(listOfSignals.at(iSignal)->Scale()));
    if ( iSignal == 0 ) treesignal[iSignal] -> Draw(myVar + " >> hsignal",thisScale + "hlt_weight*evt_weight*kf_weight*pu_weight" + myCut);
    else treesignal[iSignal] -> Draw(myVar + " >>+ hsignal",thisScale + "hlt_weight*evt_weight*kf_weight*pu_weight" + myCut);
    
    if ( drawSignal && iSignal == 0 ) leg -> AddEntry(hsignal, "Signal", "l");    
    
  }//end loop on signals
  if (xlowVec != 0) {
    for (int iBin = 1; iBin <= nBins; iBin++) hsignal->SetBinError  (iBin,hsignal->GetBinError(iBin)/hsignal->GetBinWidth(iBin));
    for (int iBin = 1; iBin <= nBins; iBin++) hsignal->SetBinContent(iBin,hsignal->GetBinContent(iBin)/hsignal->GetBinWidth(iBin));
  }
  hsignal -> SetLineColor(49);
  hsignal -> SetLineWidth(4.0);
       
  int theHistCounter = 0;
  // loop through the samples and produce the plots
  for (UInt_t iSample=0; iSample < listOfSamples.size(); iSample++) {

    //determine if the histo is first of the series
    bool isFirstOfSerie = (*listOfSamples.at(iSample)->Legend()).CompareTo(" ");
    bool isLastOfSerie = false;
    if (iSample == listOfSamples.size() - 1) isLastOfSerie = true;
    if (iSample < listOfSamples.size() - 1 && (*listOfSamples.at(iSample+1)->Legend()).CompareTo(" ") != 0) isLastOfSerie = true;
    
    //get the tree
    tree[iSample] = (TTree*) infile -> Get(listOfSamples.at(iSample)->Name()->Data());
    //if sample first of the list create a new histogram
    if (isFirstOfSerie) {
       TString thisHistName = "h_" + *(listOfSamples.at(iSample)->Name());
       //variable bin histo
       if (xlowVec != 0) hist[theHistCounter] = new TH1F(thisHistName,thisHistName,nBins,xlowVec);
       //fixed bin histo
       else hist[theHistCounter] = new TH1F(thisHistName,thisHistName,nBins,xLow,xHigh);
       hist[theHistCounter] -> Sumw2();
       hist[theHistCounter] -> SetFillColor(col[theHistCounter]);
       hist[theHistCounter] -> SetFillStyle(1001);
       theLegends.push_back(*listOfSamples.at(iSample)->Legend());
    }

    //fill the histogram
    TString thisScale = Form("%f *", *(listOfSamples.at(iSample)->Scale()));
    if (isFirstOfSerie) tree[iSample] -> Draw(myVar + " >> " + TString(hist[theHistCounter] -> GetName()),thisScale + "hlt_weight*evt_weight*kf_weight*pu_weight" + myCut);
    else tree[iSample] -> Draw(myVar + " >>+ " + TString(hist[theHistCounter] -> GetName()),thisScale + "hlt_weight*evt_weight*kf_weight*pu_weight" + myCut);
    
    //add the systematic uncertainty
    for (int iBin = 1; iBin <= nBins; iBin++) {
      float thisSyst = *(listOfSamples.at(iSample)->Syst());
      float thisError = sqrt(hist[theHistCounter]->GetBinError(iBin)*hist[theHistCounter]->GetBinError(iBin) + 
      thisSyst*thisSyst*hist[theHistCounter]->GetBinContent(iBin)*hist[theHistCounter]->GetBinContent(iBin));
      hist[theHistCounter]->SetBinError  (iBin,thisError);
    }

    //add the histogram to the stack if the last of the series:
    //either last sample or ~ sample followed by non ~ sample
    if (isLastOfSerie) {
       if (xlowVec != 0) {
         for (int iBin = 1; iBin <= nBins; iBin++) hist[theHistCounter]->SetBinError  (iBin,hist[theHistCounter]->GetBinError(iBin)/hist[theHistCounter]->GetBinWidth(iBin));
         for (int iBin = 1; iBin <= nBins; iBin++) hist[theHistCounter]->SetBinContent(iBin,hist[theHistCounter]->GetBinContent(iBin)/hist[theHistCounter]->GetBinWidth(iBin));
       }
       hs -> Add(hist[theHistCounter]);
       theHistCounter++;
    }
    
  }//end loop on samples

  //Fix the legend
  for (int iHisto = theHistCounter-1; iHisto >= 0; iHisto--) {
    leg -> AddEntry(hist[iHisto], theLegends[iHisto], "f");   
  }
  
  //get the maximum to properly set the frame
  float theMax = hdata -> GetBinContent(hdata -> GetMaximumBin()) + hdata -> GetBinError(hdata -> GetMaximumBin());
  TH1* theMCSum = (TH1*) hs->GetStack()->Last();
  float theMaxMC = theMCSum->GetBinContent(theMCSum->GetMaximumBin()) + theMCSum->GetBinError(theMCSum->GetMaximumBin());
  if (theMaxMC > theMax) theMax = theMaxMC;
  
  //prepare the ratio band and plot
  TH1* theMCRatioBand = makeRatioBand(theMCSum);
  TH1* theRatioPlot = makeRatioPlot(hdata,theMCSum);
    
  TCanvas* can = new TCanvas();
  can -> SetLogy(isLog);
  
  TPad *pad1 = new TPad("pad1","top pad",0,0.30,1,1);
  pad1->SetBottomMargin(0.02);
  pad1->SetLeftMargin(0.13);
  pad1->SetLogy(isLog);
  pad1->Draw();
  TPad *pad2 = new TPad("pad2","bottom pad",0,0.0,1,0.30);
  pad2->SetTopMargin(0.02);
  pad2->SetLeftMargin(0.13);
  pad2->SetBottomMargin(0.4);
  pad2->SetGridy();
  pad2->Draw();
  
  pad1->cd();
  hs->Draw("hist");
  hdata->Draw("same,pe");
  if (drawSignal) hsignal->Draw("same,hist");
  if (drawLegend) leg->Draw("same");
  //hs->GetXaxis()->SetTitle(myAxisNameX);
  hs->GetYaxis()->SetTitle(myAxisNameY);
  hs->GetXaxis()->SetLabelSize(0.04);
  hs->GetYaxis()->SetLabelSize(0.04);
  hs->GetXaxis()->SetLabelOffset(0.025);
  hs->GetYaxis()->SetLabelOffset(0.035);
  //hs->GetXaxis()->SetTitleOffset(1.1);
  hs->GetYaxis()->SetTitleOffset(1.1);
  hs->SetMaximum(theMax);
  if (isLog) hs->SetMinimum(0.01);
  
  pad2->cd();
  theMCRatioBand->GetXaxis()->SetTitle(myAxisNameX);
  theMCRatioBand->GetXaxis()->SetTitleSize(0.16);
  theMCRatioBand->GetXaxis()->SetTitleOffset(1.1);
  theMCRatioBand->GetXaxis()->SetLabelSize(0.12);
  theMCRatioBand->GetXaxis()->SetLabelOffset(0.07);
  theMCRatioBand->GetYaxis()->SetTitle("Data/MC");
  theMCRatioBand->GetYaxis()->SetTitleSize(0.10);
  theMCRatioBand->GetYaxis()->SetTitleOffset(0.6);
  theMCRatioBand->GetYaxis()->SetLabelSize(0.06);
  theMCRatioBand->GetYaxis()->SetLabelOffset(0.03);
  theMCRatioBand->SetFillStyle(3001);
  theMCRatioBand->SetFillColor(kBlue);
  theMCRatioBand->SetLineWidth(1);
  theMCRatioBand->SetLineColor(kBlack);
  theMCRatioBand->SetMarkerSize(0.1);
  theMCRatioBand->SetMaximum(3.);
  theMCRatioBand->SetMinimum(0.);
  theMCRatioBand->Draw("E2");
  TLine *line = new TLine(xLow,1,xHigh,1);
  line->SetLineColor(kBlack);
  line->Draw("same");
  theRatioPlot->Draw("same,pe");
  
  can->cd();
  can->Modified();
  can -> SaveAs(myName + "_lep.pdf","pdf");
  can -> SaveAs(myName + "_lep.png","png");
  
  //cleanup the memory allocation
  delete theMCSum;
  delete hs;
  delete leg;
  delete hdata;
  delete pad1;
  delete pad2;
  delete can;
  delete theMCRatioBand;
  delete theRatioPlot;
  infile -> Close();
  delete infile;
  
  return;
}
示例#23
0
文件: vhtree.C 项目: ankitm123/cmssw
void vhtree::Loop()
{
//   In a ROOT session, you can do:
//      Root > .L vhtree.C
//      Root > vhtree t
//      Root > t.GetEntry(12); // Fill t data members with entry number 12
//      Root > t.Show();       // Show values of entry 12
//      Root > t.Show(16);     // Read and show values of entry 16
//      Root > t.Loop();       // Loop on all entries
//

//     This is the loop skeleton where:
//    jentry is the global entry number in the chain
//    ientry is the entry number in the current Tree
//  Note that the argument to GetEntry must be:
//    jentry for TChain::GetEntry
//    ientry for TTree::GetEntry and TBranch::GetEntry
//
//       To read only selected branches, Insert statements like:
// METHOD1:
//    fChain->SetBranchStatus("*",0);  // disable all branches
//    fChain->SetBranchStatus("branchname",1);  // activate branchname
// METHOD2: replace line
//    fChain->GetEntry(jentry);       //read all branches
//by  b_branchname->GetEntry(ientry); //read only this branch
   if (fChain == 0) return;
   double delRMin=0.03;
   double delR=0.;
   double GenMuonPt=0.;                                                                                                            
   double delphi=0.;
   double deleta=0.;
   double RecoMuonPt=0.;
   double RecoMuonEta=0.;
   double inv_mass=0.;
   double ImpParam=0.;
   double MuonDZ=0.;
   double MuonChi2=0.;
   double SumMuonChi2=0.;
   double e1=0.;
   double e2=0.;
   double p1x=0.;
   double p2x=0.;
   double p1y=0.;
   double p2y=0.;
   double p1z=0.;
   double p2z=0.;
   double phi_1=0.;
   double phi_2=0;
   double theta_1=0;
   double theta_2=0;
   double metx=0.;
   double mety=0.;
   double p_1=0.;
   double p_2=0.;
   double x_1=0;
   double x_2=0;
   double pvis_1=0;
   double pvis_2=0;
   double inv_mass_vis=0;
   Double_t total_events=0;
   Double_t events=0;

   ofstream myfile("acceptance.file",ios::app);
   ofstream myfile2("acceptance2.file",ios::app);
   
   TH1F *h1PtReco = new TH1F("h1PtReco","Reco Muon Pt",100,0,300);
   TH1F *h1PtGen = new TH1F("h1PtGen","Gen Muon Pt",100,0,300);
   
   TH1F *h1PtLeading = new TH1F("h1PtLeading","Leading Muon Pt",100,0,100);
   TH1F *h1PtSubLeading = new TH1F("h1PtSubLeading","SubLeading Muon Pt",100,0,100);
   
   TH1F *h1PtLeadingi = new TH1F("h1PtLeadingi","Integrated Leading Muon Pt",100,0,100);
   TH1F *h1PtSubLeadingi = new TH1F("h1PtSubLeadingi","Integrated SubLeading Muon Pt",100,0,100);
   


   TH1F *h1EtaReco = new TH1F("h1EtaReco","Reco Muon Eta",100,-5,+5);
   //TH1F *h1EtaGen = new TH1F("h1EtaGen","Gen Muon Eta",100,-5,+5);
   
   TH1F *hPhiReco = new TH1F("hPhiReco","Difference in Phi between the two muons in multiples of #pi",100,-2,2);

   
   
   TH1F *hMCMatchEC = new TH1F("hMCMatchEC","Muon Pt resolution in End cap region",200,-0.5,0.5);
   TH1F *hMCMatchBa = new TH1F("hMCMatchBa","Muon Pt resolution in barrel region",200,-0.5,0.5);
   
   TH1F *hLeadMuon1 = new TH1F("hLeadMuon1","Leading Muon and Subleading Muon in EndCap",100,0,100);
   TH1F *hLeadMuon2 = new TH1F("hLeadMuon2","Leading Muon in Endcap, subleading muon in barrel",100,0,100);
   TH1F *hLeadMuon3 = new TH1F("hLeadMuon3","Leading Muon in Barrel, subleading muon in endcap",100,0,100);
   
   TH1F *hSubLeadMuon1 = new TH1F("hSubLeadMuon1","Leading Muon and Subleading Muon in EndCap",100,0,100);
   TH1F *hSubLeadMuon2 = new TH1F("hSubLeadMuon2","Leading Muon in Endcap, subleading muon in barrel",100,0,100);
   TH1F *hSubLeadMuon3 = new TH1F("hSubLeadMuon3","Leading Muon in Barrel, subleading muon in endcap",100,0,100);
   
   TH2F *h1 = new TH2F("h1","Correlation plot between Subleading and leading muon Pt(Overall)",30,0,30,30,0,30);
   TH2F *h11 = new TH2F("h11","Correlation plot between Subleading and leading muon Pt(EC(Lead), EC(sublead))",30,0,30,30,0,30);
   TH2F *h12 = new TH2F("h12","Correlation plot between Subleading and leading muon Pt(EC(Lead),Barrel(Sublead))",30,0,30,30,0,30);
   TH2F *h13 = new TH2F("h13","Correlation plot between Subleading and leading muon Pt(EC(sublead),Barrel(Lead))",30,0,30,30,0,30);
   //TH3F *h2 = new TH3F("h2","acceptance plot",300,0,300,100,0,150,100,0,1);
   TH2F *hAcceptAll = new TH2F("hAcceptAll","Overall acceptance plot",200,0,50,200,0,50);
   TH2F *hAccept1 = new TH2F("hAccept1","Leading Muon and Subleading Muon in EndCap",200,0,50,200,0,50);
   TH2F *hAccept2 = new TH2F("hAccept2","Leading Muon in Endcap, subleading muon in barrel",200,0,50,200,0,50);
   TH2F *hAccept3 = new TH2F("hAccept3","Leading Muon in Barrel, subleading muon in endcap",200,0,50,200,0,50);
   
   //TProfile2D *h2 = new TProfile2D("h2","acceptance plot",100,0,300,100,0,300,0,1);  
   //TGraph2D *t2 = new TGraph2D();
   TH1F *hInvTau = new TH1F("hInvTau","Invariant Mass plot for Taus",100,0,300);
   TH1F *hInvMuon = new TH1F("hInvMuon","Invariant Mass plot for Muons(visible)",100,0,300);

   
   
   TH1F *hImPEC = new TH1F("hImPEC","Impact parameter plot End cap",100,-0.3,0.3);
   TH1F *hImPBa = new TH1F("hImPBa","Impact parameter plot barrel",100,-0.3,0.3);
   
   TH1F *hDZEC = new TH1F("hDZEC","Muon DZ plot End cap",100,-10,10);
   TH1F *hDZBa = new TH1F("hDZBa","Muon DZ plot barrel",100,-10,10);

   TH1F *hChiEC = new TH1F("hChiEC","Muon Chi plot End cap",100,0,16);
   TH1F *hChiBa = new TH1F("hChiBa","Muon Chi plot barrel",100,0,16);

   TH1F *hImPECEr = new TH1F("hImPECEr","Error in Impact parameter plot End cap",100,0,16);
   TH1F *hImPBaEr = new TH1F("hImPBaEr","Error in Impact parameter plot barrel",100,0,16);

   //Muon eta plots for pT threshold !

   TH1F *hEtaPt10 = new TH1F("hEtaPt10","Reco Muon Eta 10",100,-3,3);
   TH1F *hEtaPt15 = new TH1F("hEtaPt15","Reco Muon Eta 15",100,-3,3);
   TH1F *hEtaPt20 = new TH1F("hEtaPt20","Reco Muon Eta 20",100,-3,3);
   TH1F *hEtaPt25 = new TH1F("hEtaPt25","Reco Muon Eta 25",100,-3,3);
   TH1F *hEtaPt30 = new TH1F("hEtaPt30","Reco Muon Eta 30",100,-3,3);
   TH1F *hEtaPt35 = new TH1F("hEtaPt35","Reco Muon Eta 35",100,-3,3);

   //2-D histograms

   TH2F *hEtaResEC = new TH2F("hEtaResEC","Eta vs MuonPt resolution in Endcap",100,-3,3,100,-5,5);
   TH2F *hEtaResBa = new TH2F("hEtaResBa","Eta vs MuonPt resolution in barrel",100,-3,3,100,-5,5);
   TH2F *hEtaResAll = new TH2F("hEtaResAll","Eta vs MuonPt resolution Overall",100,-3,3,100,-5,5);
   
   TH2F *hEtaPtEC = new TH2F("hEtaPtEC","Eta vs MuonPt in Endcap",100,-3,3,100,0,200);
   TH2F *hEtaPtBa = new TH2F("hEtaPtBa","Eta vs MuonPt in barrel",100,-3,3,100,0,200);
   TH2F *hEtaPtAll = new TH2F("hEtaPtAll","Eta vs MuonPt Overall",100,-3,3,100,0,200);
   


   //std::vector<double> leadmuonpt;
   //std::vector<double> subleadmuonpt;
   Double_t pt_cut=50.;
   Double_t bin_width=0.25;
   const int bin_size_sl=pt_cut/bin_width;
   const int bin_size_l=pt_cut/bin_width;
   
   Double_t leadmuonpt[bin_size_l]={0}; //100 is the number of bins
   Double_t subleadmuonpt[bin_size_sl]={0};
   
   Double_t leadmuonpt1[bin_size_l]={0}; //100 is the number of bins
   Double_t subleadmuonpt1[bin_size_sl]={0};
   
   Double_t leadmuonpt2[bin_size_l]={0}; //100 is the number of bins
   Double_t subleadmuonpt2[bin_size_sl]={0};
   
   Double_t leadmuonpt3[bin_size_l]={0}; //100 is the number of bins
   Double_t subleadmuonpt3[bin_size_sl]={0};

   //TFile *f1 = new TFile("histos_signal.root","RECREATE");

   
   Long64_t nentries = fChain->GetEntriesFast();
   cout<<"Number of events "<<nentries<<endl;
   int dimuon=0;
   Long64_t nbytes = 0, nb = 0;
   //for (Long64_t jentry=0;jentry<nentries;jentry++) {
   for (Long64_t jentry=0;jentry<nentries;jentry++) {
     Long64_t ientry = LoadTree(jentry);
     if (ientry < 0) break;
     nb = fChain->GetEntry(jentry);   nbytes += nb;
     
     if (nMuon!=2) continue;
     if (abs(Muon_phi[0]-Muon_phi[1] >= 2.0))continue;
     ++dimuon;
     

     if (Muon_pt[0]>Muon_pt[1]){
       h1PtLeading->Fill(Muon_pt[0]);
       h1PtSubLeading->Fill(Muon_pt[1]);
     }
     
     else if (Muon_pt[0]<Muon_pt[1]){
       h1->Fill(Muon_pt[1],Muon_pt[0]);
       cout<<Muon_pt[1]<<" "<<Muon_pt[0]<<endl;
     }
     
     

     //Different cases
     if (Muon_pt[0]>Muon_pt[1]){
	 if (((fabs(Muon_eta[0]) > 1.6) && (fabs(Muon_eta[0]) < 2.2)) && ((fabs(Muon_eta[1]) > 1.6) && (fabs(Muon_eta[1]) < 2.2))){
	   hLeadMuon1->Fill(Muon_pt[0]);
	   hSubLeadMuon1->Fill(Muon_pt[1]);
	   h1->Fill(Muon_pt[0],Muon_pt[1]);
	   h11->Fill(Muon_pt[0],Muon_pt[1]);
	   if (Muon_pt[0]<pt_cut){
	     for (int i=0;i<bin_size_l;i++){
	       if (Muon_pt[0]>=i*bin_width && Muon_pt[0]<(i+1)*bin_width){
		 leadmuonpt[i]+=1;
		 leadmuonpt1[i]+=1;
	       }
	     }
	   }
       
	   if (Muon_pt[1]<pt_cut){
	     for (int i=0;i<bin_size_sl;i++){
	       if (Muon_pt[1]>i*bin_width && Muon_pt[1]<=(i+1)*bin_width){
		 subleadmuonpt[i]+=1;
		 subleadmuonpt1[i]+=1;
	       }
	     }
	   }
	 }
	 if (((fabs(Muon_eta[0]) > 1.6) && (fabs(Muon_eta[0]) < 2.2)) && (fabs(Muon_eta[1]) < 1.6)){
	   h1->Fill(Muon_pt[0],Muon_pt[1]);
	   h12->Fill(Muon_pt[0],Muon_pt[1]);
	   hLeadMuon2->Fill(Muon_pt[0]);
	   hSubLeadMuon2->Fill(Muon_pt[1]);
	   if (Muon_pt[0]<pt_cut){
	     for (int i=0;i<bin_size_l;i++){
	       if (Muon_pt[0]>=i*bin_width && Muon_pt[0]<(i+1)*bin_width){
		 leadmuonpt[i]+=1;
		 leadmuonpt2[i]+=1;
	       }
	     }
	   }
       
	   if (Muon_pt[1]<pt_cut){
	     for (int i=0;i<bin_size_sl;i++){
	       if (Muon_pt[1]>i*bin_width && Muon_pt[1]<=(i+1)*bin_width){
		 subleadmuonpt[i]+=1;
		 subleadmuonpt2[i]+=1;
	       }
	     }
	   }
	 }
	 if ((fabs(Muon_eta[0]) < 1.6) && ((fabs(Muon_eta[1]) > 1.6) && (fabs(Muon_eta[1]) < 2.2))){
	   h1->Fill(Muon_pt[0],Muon_pt[1]);
	   h13->Fill(Muon_pt[0],Muon_pt[1]);
	   hLeadMuon3->Fill(Muon_pt[0]);
           hSubLeadMuon3->Fill(Muon_pt[1]);
	   if (Muon_pt[0]<pt_cut){
	     for (int i=0;i<bin_size_l;i++){
	       if (Muon_pt[0]>=i*bin_width && Muon_pt[0]<(i+1)*bin_width){
		 leadmuonpt[i]+=1;
		 leadmuonpt3[i]+=1;
	       }
	     }
	   }
       
	   if (Muon_pt[1]<pt_cut){
	     for (int i=0;i<bin_size_sl;i++){
	       if (Muon_pt[1]>i*bin_width && Muon_pt[1]<=(i+1)*bin_width){
		 subleadmuonpt[i]+=1;
		 subleadmuonpt3[i]+=1;
	       }
	     }
	   }
	 }
     } 
       else{
	 if (((fabs(Muon_eta[1]) > 1.6) && (fabs(Muon_eta[1]) < 2.2)) && ((fabs(Muon_eta[0]) > 1.6) && (fabs(Muon_eta[0]) < 2.2))){
	   hLeadMuon1->Fill(Muon_pt[1]);
	   hSubLeadMuon1->Fill(Muon_pt[0]);
	 }
	 if (((fabs(Muon_eta[1]) > 1.6) && (fabs(Muon_eta[1]) < 2.2)) && (fabs(Muon_eta[0]) < 1.6)){
	   hLeadMuon2->Fill(Muon_pt[1]);
	   hSubLeadMuon2->Fill(Muon_pt[0]);
	 }
	 if ((fabs(Muon_eta[1]) < 1.6) && ((fabs(Muon_eta[0]) > 1.6) && (fabs(Muon_eta[0]) < 2.2))){
	   hLeadMuon3->Fill(Muon_pt[1]);
           hSubLeadMuon3->Fill(Muon_pt[0]);
	 }
      
       }
     for (int i=0;i<nMuon; i++){
       RecoMuonPt=Muon_pt[i];
       RecoMuonEta=Muon_eta[i];
       GenMuonPt=Muon_ptgen[i];
       ImpParam=Muon_trkD0[i];
       MuonDZ=Muon_trkDz[i];
       MuonChi2=Muon_globalChi2[i];
     
       if ((fabs(RecoMuonEta) > 1.5) && (fabs(RecoMuonEta) < 2.2)){
	 hMCMatchEC->Fill((GenMuonPt-RecoMuonPt)/GenMuonPt);
	 hImPEC->Fill(ImpParam);
	 hDZEC->Fill(MuonDZ);
	 hChiEC->Fill(MuonChi2);
	 hEtaPtEC->Fill(RecoMuonEta,RecoMuonPt);
	 //hEtaResEC->Fill(RecoMuonPt-GenMuonPt,RecoMuonEta);
       }
       if ((fabs(Muon_eta[i]) < 1.6)){
	 hMCMatchBa->Fill((GenMuonPt-RecoMuonPt)/GenMuonPt);
	 hImPBa->Fill(ImpParam);
	 hDZBa->Fill(MuonDZ);
	 hChiBa->Fill(MuonChi2);
	 hEtaPtBa->Fill(RecoMuonEta,RecoMuonPt);
       }
       h1PtGen->Fill(GenMuonPt);
       h1PtReco->Fill(RecoMuonPt);
       h1EtaReco->Fill(RecoMuonEta);
       hEtaPtAll->Fill(RecoMuonEta,RecoMuonPt);
       if (RecoMuonPt>10.)hEtaPt10->Fill(RecoMuonEta);  
       if (RecoMuonPt>15.)hEtaPt15->Fill(RecoMuonEta);  
       if (RecoMuonPt>20.)hEtaPt20->Fill(RecoMuonEta);
       if (RecoMuonPt>25.)hEtaPt25->Fill(RecoMuonEta);         
       if (RecoMuonPt>30.)hEtaPt30->Fill(RecoMuonEta);
       if (RecoMuonPt>35.)hEtaPt35->Fill(RecoMuonEta);  
       //if ()
     }
    
   }
   cout<<"Number of dimuon events "<<dimuon<<" BR of di tau to dimuon "<<((float)dimuon/(float)nentries)*100<<endl;
   
   //Overall
   /*
   total_events=0;
   events=0;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       if(leadmuonpt[i]!=0 && subleadmuonpt[j]!=0)total_events+=leadmuonpt[i]*subleadmuonpt[j];
     }
   }
   cout<<total_events<<endl;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       events=0;
       for (int k=i;k<bin_size_l;k++){
	 for (int l=j;l<k;l++){
	   if(leadmuonpt[k]!=0 && subleadmuonpt[l]!=0)events+=leadmuonpt[k]*subleadmuonpt[l];
	 }
       }
       hAcceptAll->Fill(i*bin_width,j*bin_width,(Double_t)events/(Double_t)total_events);
     }
   }
   

   //Case-1
   
   total_events=0;
   events=0;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       if(leadmuonpt1[i]!=0 && subleadmuonpt1[j]!=0)total_events+=leadmuonpt1[i]*subleadmuonpt1[j];
     }
   }
   cout<<total_events<<endl;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       events=0;
       for (int k=i;k<bin_size_l;k++){
	 for (int l=j;l<k;l++){
	   if(leadmuonpt1[k]!=0 && subleadmuonpt1[l]!=0)events+=leadmuonpt1[k]*subleadmuonpt1[l];
	 }
       }
       hAccept1->Fill(i*bin_width,j*bin_width,(Double_t)events/(Double_t)total_events);
     }
   }
   
   //Case-2
   total_events=0;
   events=0;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       if(leadmuonpt2[i]!=0 && subleadmuonpt2[j]!=0)total_events+=leadmuonpt2[i]*subleadmuonpt2[j];
     }
   }
   cout<<total_events<<endl;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       events=0;
       for (int k=i;k<bin_size_l;k++){
	 for (int l=j;l<k;l++){
	   if(leadmuonpt2[k]!=0 && subleadmuonpt2[l]!=0)events+=leadmuonpt2[k]*subleadmuonpt2[l];
	 }
       }
       hAccept2->Fill(i*bin_width,j*bin_width,(Double_t)events/(Double_t)total_events);
     }
   }

   //Case-3

   total_events=0;
   events=0;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       if(leadmuonpt3[i]!=0 && subleadmuonpt3[j]!=0)total_events+=leadmuonpt3[i]*subleadmuonpt3[j];
     }
   }
   cout<<total_events<<endl;
   for (int i=0;i<bin_size_l;i++){
     for (int j=0;j<i;j++){
       events=0;
       for (int k=i;k<bin_size_l;k++){
	 for (int l=j;l<k;l++){
	   if(leadmuonpt3[k]!=0 && subleadmuonpt3[l]!=0)events+=leadmuonpt3[k]*subleadmuonpt3[l];
	 }
       }
       //myfile2<<i<<" "<<j<<" "<<" "<<events<<" "<<total_events<<" "<<(Double_t)events/(Double_t)total_events<<endl;
       //myfile2<<i*bin_width<<" "<<j*bin_width<<" "<<(Double_t)events/(Double_t)total_events<<endl;
       hAccept3->Fill(i*bin_width,j*bin_width,(Double_t)events/(Double_t)total_events);
       //hAccept1->Fill(i*bin_width,j*bin_width);
     }
   }
   hAcceptAll->Write();
   
   //Time to beautify most of the plots
   hLeadMuon1->SetLineColor(1);
   hSubLeadMuon1->SetLineColor(4);
   hLeadMuon1->SetXTitle("Reco. Muon p_{T} in GeV/c");
   hSubLeadMuon1->SetXTitle("Reco. Muon p_{T} in GeV/c");
   hLeadMuon1->SetYTitle("Number of Events/GeV");
   hSubLeadMuon1->SetYTitle("Number of Events/GeV");
   hSubLeadMuon1->Draw();
   gPad->Update();
   hLeadMuon1->Draw();          //draw hist_2 first as it has a larger range
   gPad->Update();


   TPaveStats *tps1 = (TPaveStats*) hLeadMuon1->FindObject("stats");
   tps1->SetName("Hist1 Stats");
   double X1 = tps1->GetX1NDC();
   double Y1 = tps1->GetY1NDC();
   double X2 = tps1->GetX2NDC();
   double Y2 = tps1->GetY2NDC();
  
   TPaveStats *tps2 = (TPaveStats*) hSubLeadMuon1->FindObject("stats");
   tps2->SetTextColor(kRed);
   tps2->SetLineColor(kRed);
   tps2->SetX1NDC(X1);
   tps2->SetX2NDC(X2);
   tps2->SetY1NDC(Y1-(Y2-Y1));
   tps2->SetY2NDC(Y1);
   
  
  
   hSubLeadMuon1->Draw();
   hLeadMuon1->Draw("same");          //draw hist_2 first as it has a larger range
   tps2->Draw("same");
   tps1->Draw("same");
   
   leg_hist = new TLegend(0.4712644,0.5886076,0.7600575,0.778481,NULL,"brNDC");
   leg_hist->SetHeader("p_{T} histograms for case 1");
   leg_hist->SetFillColor(0);
   leg_hist->AddEntry(hLeadMuon1,"leading muon p_{T}","l");
   leg_hist->AddEntry(hSubLeadMuon1,"subleading muon p_{T}","l");
   leg_hist->SetTextSize(0.03);
   leg_hist->Draw();
  
   c1->SaveAs("case1.pdf");
   c1->Clear();
   

   hLeadMuon2->SetLineColor(1);
   hSubLeadMuon2->SetLineColor(4);
   hLeadMuon2->SetXTitle("Reco Muon p_{T} in GeV/c");
   hSubLeadMuon2->SetXTitle("Reco Muon p_{T} in GeV/c");
   hLeadMuon2->SetYTitle("Number of Events/GeV");
   hSubLeadMuon2->SetYTitle("Number of Events/GeV");
   hSubLeadMuon2->Draw();
   gPad->Update();
   hLeadMuon2->Draw();
   gPad->Update();
   //draw hist_2 first as it has a larger range
   TPaveStats *tps1 = (TPaveStats*) hLeadMuon2->FindObject("stats");
   tps1->SetName("Hist1 Stats");
   double X1 = tps1->GetX1NDC();
   double Y1 = tps1->GetY1NDC();
   double X2 = tps1->GetX2NDC();
   double Y2 = tps1->GetY2NDC();
   
   TPaveStats *tps2 = (TPaveStats*) hSubLeadMuon2->FindObject("stats");
   tps2->SetTextColor(kRed);
   tps2->SetLineColor(kRed);
   tps2->SetX1NDC(X1);
   tps2->SetX2NDC(X2);
   tps2->SetY1NDC(Y1-(Y2-Y1));
   tps2->SetY2NDC(Y1);
   
  
  
   hSubLeadMuon2->Draw();
   hLeadMuon2->Draw("same");          //draw hist_2 first as it has a larger range
   tps2->Draw("same");
   tps1->Draw("same");
   
   leg_hist = new TLegend(0.4712644,0.5886076,0.7600575,0.778481,NULL,"brNDC");
   leg_hist->SetHeader("p_{T} histograms for case 2");
   leg_hist->SetFillColor(0);
   leg_hist->AddEntry(hLeadMuon2,"leading muon p_{T}","l");
   leg_hist->AddEntry(hSubLeadMuon2,"subleading muon p_{T}","l");
   leg_hist->SetTextSize(0.03);
   leg_hist->Draw();
   
   c1->SaveAs("case2.pdf");
  
   
   hLeadMuon3->SetLineColor(1);
   hSubLeadMuon3->SetLineColor(4);
   hLeadMuon3->SetXTitle("Reco Muon p_{T} in GeV/c");
   hSubLeadMuon3->SetXTitle("Reco Muon p_{T} in GeV/c");
   hLeadMuon3->SetYTitle("Number of Events/GeV");
   hSubLeadMuon3->SetYTitle("Number of Events/GeV");
   hSubLeadMuon3->Draw();
   gPad->Update();
   hLeadMuon3->Draw();          //draw hist_2 first as it has a larger range
   gPad->Update();
   
   TPaveStats *tps1 = (TPaveStats*) hLeadMuon3->FindObject("stats");
   tps1->SetName("Hist1 Stats");
   double X1 = tps1->GetX1NDC();
   double Y1 = tps1->GetY1NDC();
   double X2 = tps1->GetX2NDC();
   double Y2 = tps1->GetY2NDC();
   
   TPaveStats *tps2 = (TPaveStats*) hSubLeadMuon3->FindObject("stats");
   tps2->SetTextColor(kRed);
   tps2->SetLineColor(kRed);
   tps2->SetX1NDC(X1);
   tps2->SetX2NDC(X2);
   tps2->SetY1NDC(Y1-(Y2-Y1));
   tps2->SetY2NDC(Y1);
   
   
   
   hSubLeadMuon3->Draw();
   hLeadMuon3->Draw("same");          //draw hist_2 first as it has a larger range
   tps2->Draw("same");
   tps1->Draw("same");
   
   
   leg_hist = new TLegend(0.4712644,0.5886076,0.7600575,0.778481,NULL,"brNDC");
   leg_hist->SetHeader("p_{T} histograms for case 3");
   leg_hist->SetFillColor(0);
   leg_hist->AddEntry(hLeadMuon3,"leading muon p_{T}","l");
   leg_hist->AddEntry(hSubLeadMuon3,"subleading muon p_{T}","l");
   leg_hist->SetTextSize(0.03);
   leg_hist->Draw();
   
   c1->SaveAs("case3.pdf");
   c1->Clear();
   
   //pT resolution plots

   hMCMatchEC->SetLineColor(1);
   
   hMCMatchEC->SetXTitle("p_{T}^{gen}-p_{T}^{reco}/p_{T}^{gen}");
   hMCMatchEC->Draw();          //draw hist_2 first as it has a larger range
   hMCMatchEC->Draw("esame");          //draw hist_2 first as it has a larger range
   c1->SaveAs("plot_res_1.pdf");
   c1->Clear();

   hMCMatchBa->SetLineColor(1);
   
   hMCMatchBa->SetXTitle("p_{T}^{gen}-p_{T}^{reco}/p_{T}^{gen}");
   hMCMatchBa->Draw();          //draw hist_2 first as it has a larger range
   hMCMatchBa->Draw("esame");          //draw hist_2 first as it has a larger range
   c1->SaveAs("plot_res_2.pdf");
   c1->Clear();

   //Acceptance plots
   
   //Overall Acceptance
   
   hAcceptAll->SetXTitle("Reco. leading muon p_{T} in GeV/c");
   hAcceptAll->SetYTitle("Reco. subleading muon p_{T} in GeV/c");
  //hAcceptAll->SetZTitle("Kinematic acceptance");
   hAcceptAll->SetStats(0);
   hAcceptAll->Draw("cont3 colz");
   //HLT_PATH Mu17_Mu8
   
   Int_t a=hAcceptAll->GetXaxis()->FindBin(17);
   Int_t b = hAcceptAll->GetYaxis()->FindBin(8);
   Double_t c = hAcceptAll->GetBinContent(a,b);
   //Double_t a = hAcceptAll->GetBinContent(hAcceptAll->GetXaxis()->FindBin(17),hAcceptAll->GetYaxis()->FindBin(8)));
   //HLT_PATH Mu13_Mu8
   //Double_t f=hAcceptAll->GetBinContent(
   Int_t d = hAcceptAll->GetXaxis()->FindBin(13);
   Int_t e = hAcceptAll->GetYaxis()->FindBin(8);
   Double_t f = hAcceptAll->GetBinContent(d,e);
  //Offline Cuts
  
   Int_t g=hAcceptAll->GetXaxis()->FindBin(20);
   Int_t h=hAcceptAll->GetYaxis()->FindBin(10);
   Double_t z=hAcceptAll->GetBinContent(g,h);
  //Double_t i=GetBinContenthAcceptAll->GetXaxis()->FindBin(20),hAcceptAll->GetYaxis()->FindBin(10));

   cout<<c<<" "<<f<<" "<<z<<endl;
  
  //Double_t m=hAcceptAll->GetBinContent(k,l);
  //draw hist_2 first as it has a larger range
  
   TLatex latex;
  //latex.DrawLatex(17,8,TString::Format("#bullet %f ",a));
  //latex.DrawLatex(17,8,TString::Format("#bullet %2f %",c*100));
   latex.DrawLatex(17,8,"#bullet 64%");
   latex.DrawLatex(13,8,"#diamond 72%");
   latex.DrawLatex(20,10,"#color[2]{#bullet} 43%");
  //latex.DrawLatex(17,8,TString::Format("%f",c));
  //latex.DrawLatex(17,8,TString::Format("%f",c));
  //latex.DrawLatex(13,8,TString::Format("#diamond %f ",f));
  
  //latex.DrawLatex(20,10,TString::Format("#circ %f ",i));
  
   latex.DrawLatex(3,22,"#bullet");
   latex.DrawLatex(2.83,25,"#diamond");
  
  
  
   latex.DrawLatex(4,28,"#scale[0.8]{HLT Paths(Run-1)}");
   latex.DrawLatex(4,22,"#scale[0.8]{Mu17_Mu8 (Luminosity 19.1 fb^{-1})}");
   latex.DrawLatex(4,25,"#scale[0.8]{Mu13_Mu8 (Luminosity 3.7 fb^{-1})}");
  
   latex.DrawLatex(4,19,"#scale[0.8]{Offline selection}");
   latex.DrawLatex(3,16,"#color[2]{#bullet}");
   latex.DrawLatex(4,16,"#scale[0.8]{Mu20_Mu10}");
   c1->SaveAs("acceptance_2d_all_cont3.pdf");
  
   //Case-1
   */
}
示例#24
0
void makeTable2(int nbins = 100, const string label = "HFtowersPlusTrunc", const char * tag = "CentralityTable_HFplus100_PA2012B_v538x01_offline", bool isMC = false, int runNum = 1) {

 TH1D::SetDefaultSumw2();

 //Intput files with HiTrees
 const int nTrees = 1;
 //string inFileNames[nTrees] = {"/tmp/azsigmon/HiForest_pPb_Hijing_NEWFIX_v2.root"};
 //string inFileNames[nTrees] = {"/tmp/azsigmon/HiForest_pPb_Epos_336800.root"};
 string inFileNames[nTrees] = {"/tmp/azsigmon/PA2013_HiForest_Express_r0_pilot_minbias_v0.root"};
 TChain * t = new TChain("hiEvtAnalyzer/HiTree");
 for (int i = 0; i<nTrees; i++) {
    t->Add(inFileNames[i].data());
 }

 //Output files and tables
 TFile * outFile = new TFile("out/datatables_Glauber2012B_d20130121_v5.root","recreate");
 //TFile * outFile = new TFile("out/tables_Ampt_d20121115_v3.root","update");
 //TFile * outFile = new TFile("out/tables_Epos_d20121115_v3.root","update");
 //TFile * outFile = new TFile("out/tables_Hijing_d20130119_v4.root","update");
 TDirectory* dir = outFile->mkdir(tag);
 dir->cd();
 TNtuple * nt = new TNtuple("nt","","value:bin:b:npart:ncoll:nhard");
 CentralityBins * bins = new CentralityBins(Form("run%d",runNum), tag, nbins);
 bins->table_.reserve(nbins);

 ofstream txtfile("out/output.txt");
 txtfile << "First input tree: " << inFileNames[0].data() << endl;

 //For data extra inputfile with Glauber centrality table and efficiency file
 TFile * effFile;
 TH1F * hEff; 
 TFile * inputMCfile;
 CentralityBins* inputMCtable;
 if(!isMC){
   //effFile = new TFile("out/efficiencies_Ampt.root","read");
   //effFile = new TFile("out/efficiencies_Hijing.root","read");
   effFile = new TFile("out/efficiencies_EposLHC_v2.root","read");
   hEff = (TH1F*)effFile->Get(Form("%s/hEff",label.data()));
   //inputMCfile = new TFile("out/tables_Glauber2012_AmptResponse_d20121115_v3.root","read");
   //inputMCfile = new TFile("out/tables_Glauber2012_HijingResponse_d20121115_v3.root","read");
   inputMCfile = new TFile("out/tables_Glauber2012B_EposLHCResponse_d20130118_v4.root","read");
   inputMCtable = (CentralityBins*)inputMCfile->Get(Form("CentralityTable_%s_SmearedGlauber_v4/run1",label.data()));
   //txtfile << "Using AMPT efficiency and AMPT smeared Glauber table" << endl << endl;
   txtfile << "Using EPOS efficiency and EPOS smeared Glauber table" << endl << endl;
   //txtfile << "Using HIJING efficiency and HIJING smeared Glauber table" << endl << endl;
 }

 //Setting up variables and branches
 double binboundaries[nbins+1];
 vector<float> values;
 TH1F * hist;
 if(!isMC) hist = new TH1F("hist","",hEff->GetNbinsX(),hEff->GetBinLowEdge(1),hEff->GetBinLowEdge(hEff->GetNbinsX()));

 float vtxZ, b, npart, ncoll, nhard, hf, hfplus, hfpluseta4, hfminuseta4, hfminus, hfhit, ee, eb;
 int run, npix, npixtrks, ntrks;
 t->SetBranchAddress("vz",&vtxZ);
 t->SetBranchAddress("run",&run);
 if(isMC){
    t->SetBranchAddress("b",&b);
    t->SetBranchAddress("Npart",	&npart);
    t->SetBranchAddress("Ncoll",	&ncoll);
    t->SetBranchAddress("Nhard",	&nhard);
 }
 t->SetBranchAddress("hiHF",		&hf);
 t->SetBranchAddress("hiHFplus",	&hfplus);
 t->SetBranchAddress("hiHFplusEta4",	&hfpluseta4);
 t->SetBranchAddress("hiHFminus",	&hfminus);
 t->SetBranchAddress("hiHFminusEta4",	&hfminuseta4);
 t->SetBranchAddress("hiHFhit",		&hfhit);
 t->SetBranchAddress("hiEE",		&ee);
 t->SetBranchAddress("hiEB",		&eb);
 t->SetBranchAddress("hiNpix",		&npix);
 t->SetBranchAddress("hiNpixelTracks",	&npixtrks);
 t->SetBranchAddress("hiNtracks",	&ntrks);
 //t->SetBranchAddress("hiNtracksOffline",	&ntrks);

 bool binB = label.compare("b") == 0;
 bool binNpart = label.compare("Npart") == 0;
 bool binNcoll = label.compare("Ncoll") == 0;
 bool binNhard = label.compare("Nhard") == 0;
 bool binHF = label.compare("HFtowers") == 0;
 bool binHFplus = label.compare("HFtowersPlus") == 0;
 bool binHFminus = label.compare("HFtowersMinus") == 0;
 bool binHFplusTrunc = label.compare("HFtowersPlusTrunc") == 0;
 bool binHFminusTrunc = label.compare("HFtowersMinusTrunc") == 0;
 bool binNpix = label.compare("PixelHits") == 0;
 bool binNpixTrks = label.compare("PixelTracks") == 0;
 bool binNtrks = label.compare("Tracks") == 0;

 //Event loop
 unsigned int Nevents = t->GetEntries();
 txtfile << "Number of events = " << Nevents << endl << endl;
 for(unsigned int iev = 0; iev < Nevents; iev++) {
   if(iev%10000 == 0) cout<<"Processing event: " << iev << endl;
   t->GetEntry(iev);

   //if(run!=runNum) continue;

   float parameter = -1;
   if(binB) parameter = b;
   if(binNpart) parameter = npart;
   if(binNcoll) parameter = ncoll;
   if(binNhard) parameter = nhard;
   if(binHF) parameter = hf;
   if(binHFplus) parameter = hfplus;
   if(binHFminus) parameter = hfminus;
   if(binHFplusTrunc) parameter = hfpluseta4;
   if(binHFminusTrunc) parameter = hfminuseta4;
   if(binNpix) parameter = npix;
   if(binNpixTrks) parameter = npixtrks;
   if(binNtrks) parameter = ntrks;

   values.push_back(parameter);

   if(!isMC) {
     hist->Fill(parameter);
   }

 }

 //Sorting the centrality variable vector
 if(binB) sort(values.begin(),values.end(),descend);
 else sort(values.begin(),values.end());

 //Finding the bin boundaries
 txtfile << "-------------------------------------" << endl;
 txtfile << label.data() << " based cuts are: " << endl;
 txtfile << "(";

 int size = values.size();
 binboundaries[nbins] = values[size-1];

 if(isMC) {
   for(int i = 0; i < nbins; i++) {
      int entry = (int)(i*(size/nbins));
      if(entry < 0 || i == 0) binboundaries[i] = 0;
      else binboundaries[i] = values[entry];
   }
 }
 else {
      TH1F * corr = (TH1F*)hist->Clone("corr");
      //TCanvas *c1 = new TCanvas();
      //c1->SetLogy();
      //corr->DrawCopy("hist");
      for (int j=1; j<corr->GetNbinsX(); j++) {
        if (hEff->GetBinContent(j) != 0) {
          corr->SetBinContent(j,corr->GetBinContent(j)/hEff->GetBinContent(j));
          corr->SetBinError(j,corr->GetBinError(j)/hEff->GetBinContent(j));
        }
      }
      //corr->SetLineColor(2);
      //corr->DrawCopy("hist same");
      //cout << "total integral = " << corr->Integral();
      float prev = 0;
      binboundaries[0] = 0;
      int j = 1;
      for (int i = 1; i < corr->GetNbinsX(); i++) {
        if(j>=nbins) continue;
        float a = corr->Integral(1,i,"");
        a = a/corr->Integral();
	//if(i<100) cout << i << " bin in x fraction of total integral = " << a << " j = " << j << endl;
        if (a > (float)j/nbins && prev < (float)j/nbins) {
		binboundaries[j] = corr->GetBinLowEdge(i+1);
		j++;
	}
        prev = a;
      }
 }
 for(int i = 0; i < nbins; i++) {
  if(binboundaries[i] < 0) binboundaries[i] = 0;
  txtfile << binboundaries[i] << ", ";
 }
 txtfile << binboundaries[nbins] << ")" << endl << "-------------------------------------" << endl;

 //***Determining Glauber results for MC and filling the table***
 if(isMC) {

  dir->cd();
  TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,40,0,40);
  TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,40,0,40);
  TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,50,0,50);
  TH2D* hb = new TH2D("hb","",nbins,binboundaries,600,0,30);

  for(unsigned int iev = 0; iev < Nevents; iev++) {
     if( iev % 5000 == 0 ) cout<<"Processing event : " << iev << endl;
     t->GetEntry(iev);

     float parameter = -1;
     if(binB) parameter = b;
     if(binNpart) parameter = npart;
     if(binNcoll) parameter = ncoll;
     if(binNhard) parameter = nhard;
     if(binHF) parameter = hf;
     if(binHFplus) parameter = hfplus;
     if(binHFminus) parameter = hfminus;
     if(binHFplusTrunc) parameter = hfpluseta4;
     if(binHFminusTrunc) parameter = hfminuseta4;
     if(binNpix) parameter = npix;
     if(binNpixTrks) parameter = npixtrks;
     if(binNtrks) parameter = ntrks;

     hNpart->Fill(parameter,npart);
     hNcoll->Fill(parameter,ncoll);
     hNhard->Fill(parameter,nhard);
     hb->Fill(parameter,b);
     int bin = hNpart->GetXaxis()->FindBin(parameter) - 1;
     if(bin < 0) bin = 0;
     if(bin >= nbins) bin = nbins - 1;
     nt->Fill(parameter,bin,b,npart,ncoll,nhard);
  }

  TF1* fGaus = new TF1("fb","gaus(0)",0,2);
  fitSlices(hNpart,fGaus);
  fitSlices(hNcoll,fGaus);
  fitSlices(hNhard,fGaus);
  fitSlices(hb,fGaus);

  TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1");
  TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2");
  TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1");
  TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2");
  TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1");
  TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2");
  TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1");
  TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2");

  txtfile<<"-------------------------------------"<<endl;
  txtfile<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl;
  for(int i = 0; i < nbins; i++){
     int ii = nbins-i;
     bins->table_[i].n_part_mean = hNpartMean->GetBinContent(ii);
     bins->table_[i].n_part_var = hNpartSigma->GetBinContent(ii);
     bins->table_[i].n_coll_mean = hNcollMean->GetBinContent(ii);
     bins->table_[i].n_coll_var = hNcollSigma->GetBinContent(ii);
     bins->table_[i].b_mean = hbMean->GetBinContent(ii);
     bins->table_[i].b_var = hbSigma->GetBinContent(ii);
     bins->table_[i].n_hard_mean = hNhardMean->GetBinContent(ii);
     bins->table_[i].n_hard_var = hNhardSigma->GetBinContent(ii);
     bins->table_[i].bin_edge = binboundaries[ii-1];

     txtfile << i << " " << hNpartMean->GetBinContent(ii) << " " << hNpartSigma->GetBinContent(ii) << " " << hNcollMean->GetBinContent(ii) << " " << hNcollSigma->GetBinContent(ii) << " " << hbMean->GetBinContent(ii) << " " <<hbSigma->GetBinContent(ii) << " " << binboundaries[ii-1] << " " <<endl;
  }
  txtfile<<"-------------------------------------"<<endl;

 } //***end of MC part***

 else { //***Data table with inputMCtable***

    txtfile<<"-------------------------------------"<<endl;
    txtfile<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl;
    for(int i = 0; i < nbins; i++){
      int ii = nbins-i;
      bins->table_[i].n_part_mean = inputMCtable->NpartMeanOfBin(i);
      bins->table_[i].n_part_var = inputMCtable->NpartSigmaOfBin(i);
      bins->table_[i].n_coll_mean = inputMCtable->NcollMeanOfBin(i);
      bins->table_[i].n_coll_var = inputMCtable->NcollSigmaOfBin(i);
      bins->table_[i].b_mean = inputMCtable->bMeanOfBin(i);
      bins->table_[i].b_var = inputMCtable->bSigmaOfBin(i);
      bins->table_[i].n_hard_mean = inputMCtable->NhardMeanOfBin(i);
      bins->table_[i].n_hard_var = inputMCtable->NhardSigmaOfBin(i);
      bins->table_[i].ecc2_mean  = inputMCtable->eccentricityMeanOfBin(i);
      bins->table_[i].ecc2_var = inputMCtable->eccentricitySigmaOfBin(i);
      bins->table_[i].bin_edge = binboundaries[ii-1];

      txtfile << i << " " << bins->table_[i].n_part_mean << " " << bins->table_[i].n_part_var << " " << bins->table_[i].n_coll_mean << " " << bins->table_[i].n_coll_var << " " <<bins->table_[i].b_mean << " " << bins->table_[i].b_var << " " << bins->table_[i].n_hard_mean << " " << bins->table_[i].n_hard_var << " " << bins->table_[i].bin_edge << " " << endl;
    }
    txtfile<<"-------------------------------------"<<endl;

 } //***end of Data part***

 outFile->cd();
 dir->cd();
 bins->Write();
 nt->Write();  
 bins->Delete();
 outFile->Write();
 txtfile.close();

}
示例#25
0
文件: eta1.C 项目: camendola/macro
void eta1(double pt1min, double pt2min, double METmin){


  TLegend* leg = new TLegend(0.13,0.6,0.87,0.87);
  leg->SetNColumns(3);
  leg->SetBorderSize(0);
  leg->SetFillStyle(0);
  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);

  TFile *data =  TFile::Open("./25ns_2246inv_v3/DoubleEG.root","READ");
  TFile *sig1 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP600.root","READ");
  TFile *sig2 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP800.root","READ");
  TFile *sig3 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1000.root","READ");
  TFile *sig4 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1200.root","READ");
  TFile *sig5 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1400.root","READ");
  TFile *sig6 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP1700.root","READ");
  TFile *sig7 = TFile::Open("./25ns_2246inv_v3/2HDM_mZP2500.root","READ");


  TFile *bkg1 =  TFile::Open("./25ns_2246inv_v3/DiPhoton.root","READ"); 
  TFile *bkg2 =  TFile::Open("./25ns_2246inv_v3/DYJetsToLL.root","READ");
  TFile *bkg3 =  TFile::Open("./25ns_2246inv_v3/GJets.root","READ");  
  TFile *bkg4 =  TFile::Open("./25ns_2246inv_v3/GluGluHToGG.root","READ");
  TFile *bkg5 =  TFile::Open("./25ns_2246inv_v3/QCD.root","READ");
  TFile *bkg6 =  TFile::Open("./25ns_2246inv_v3/VH.root","READ");
  TFile *bkg7 =  TFile::Open("./25ns_2246inv_v3/ttHJetToGG.root","READ");
  TFile *bkg8 =  TFile::Open("./25ns_2246inv_v3/VBFHToGG.root","READ");
  TFile *bkg9 =  TFile::Open("./25ns_2246inv_v3/TGJets.root","READ");
  TFile *bkg10 =  TFile::Open("./25ns_2246inv_v3/TTGJets.root","READ");
  TFile *bkg11 =  TFile::Open("./25ns_2246inv_v3/WGToLNuG.root","READ");
  TFile *bkg12 =  TFile::Open("./25ns_2246inv_v3/ZGTo2LG.root","READ");
 
  TTree *tree_data = (TTree*) data->Get("DiPhotonTree");

  TTree *tree_sig1 = (TTree*) sig1->Get("DiPhotonTree"); 
  TTree *tree_sig2 = (TTree*) sig2->Get("DiPhotonTree"); 
  TTree *tree_sig3 = (TTree*) sig3->Get("DiPhotonTree"); 
  TTree *tree_sig4 = (TTree*) sig4->Get("DiPhotonTree"); 
  TTree *tree_sig5 = (TTree*) sig5->Get("DiPhotonTree"); 
  TTree *tree_sig6 = (TTree*) sig6->Get("DiPhotonTree");
  TTree *tree_sig7 = (TTree*) sig7->Get("DiPhotonTree");  


  TTree *tree_bkg1 = (TTree*) bkg1->Get("DiPhotonTree");
  TTree *tree_bkg2 = (TTree*) bkg2->Get("DiPhotonTree");
  TTree *tree_bkg3 = (TTree*) bkg3->Get("DiPhotonTree");
  TTree *tree_bkg4 = (TTree*) bkg4->Get("DiPhotonTree");
  TTree *tree_bkg5 = (TTree*) bkg5->Get("DiPhotonTree");
  TTree *tree_bkg6 = (TTree*) bkg6->Get("DiPhotonTree");
  TTree *tree_bkg7 = (TTree*) bkg7->Get("DiPhotonTree");
  TTree *tree_bkg8 = (TTree*) bkg8->Get("DiPhotonTree");
  TTree *tree_bkg9 = (TTree*) bkg9->Get("DiPhotonTree");
  TTree *tree_bkg10 = (TTree*) bkg10->Get("DiPhotonTree");
  TTree *tree_bkg11 = (TTree*) bkg11->Get("DiPhotonTree");
  TTree *tree_bkg12 = (TTree*) bkg12->Get("DiPhotonTree");

  TCanvas *c1 = new TCanvas("c1","",500,600);
  TPad *mainPad = new TPad("mainPad","",0,0.3,1,1); 
  TPad *smallPad = new TPad("smallPad","",0,0.05,1,0.3);
  mainPad->SetBottomMargin(0.015);
 
  
  smallPad->SetTopMargin(0.05); 
smallPad->SetBottomMargin(0.25); 

  c1->cd();
  
  mainPad->Draw();
  mainPad->cd(); 
 
  
  
  
  
  
  
  // gPad->SetLogy();  
  
  TCut mggmax = "mgg<180";
  TCut mggmin = "mgg>100";
  TCut mggblind = "((mgg<115)||(mgg>135))";

  TCut pt1Cut = Form("pt1/mgg>%lf",pt1min);
  TCut pt2Cut = Form("pt2/mgg>%lf",pt2min);
  TCut METCut = Form("t1pfmet>%lf",METmin);
  TCut eveto1 = "eleveto1 == 1";
  TCut eveto2 = "eleveto2 == 1";
  TCut eveto = eveto1 && eveto2;
  TCut genmatch = "((genmatch1==1 && genmatch2==0)||(genmatch1==0 && genmatch2==1)||(genmatch1==0 && genmatch2==0))";  
  TCut metF = "((metF_GV==1) && (metF_HBHENoise==1) && (metF_HBHENoiseIso==1) && (metF_CSC==1) && (metF_eeBadSC==1))";  
  
  tree_data->Draw("(eta1)>>hdata(15,-3,3)",(mggmax && mggmin && metF&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hdata =(TH1F*)gPad->GetPrimitive("hdata");
  
  
  tree_sig1->Draw("(eta1)>>h1(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h1 =(TH1F*)gPad->GetPrimitive("h1");
  tree_sig2->Draw("(eta1)>>h2(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h2 =(TH1F*)gPad->GetPrimitive("h2");
  tree_sig3->Draw("(eta1)>>h3(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h3 =(TH1F*)gPad->GetPrimitive("h3");
  tree_sig4->Draw("(eta1)>>h4(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h4 =(TH1F*)gPad->GetPrimitive("h4");
  tree_sig5->Draw("(eta1)>>h5(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h5 =(TH1F*)gPad->GetPrimitive("h5");
  tree_sig6->Draw("(eta1)>>h6(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h6 =(TH1F*)gPad->GetPrimitive("h6");
  tree_sig7->Draw("(eta1)>>h7(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *h7 =(TH1F*)gPad->GetPrimitive("h7");
  
  
  tree_bkg1->Draw("(eta1)>>hbkg1(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg1 =(TH1F*)gPad->GetPrimitive("hbkg1");
  tree_bkg2->Draw("(eta1)>>hbkg2(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));  
  TH1F *hbkg2 =(TH1F*)gPad->GetPrimitive("hbkg2");
  tree_bkg3->Draw("(eta1)>>hbkg3(15,-3,3)","weight"*(mggmin && mggmax && genmatch&& METCut &&pt1Cut && pt2Cut&& eveto));  
  TH1F *hbkg3 =(TH1F*)gPad->GetPrimitive("hbkg3");
  tree_bkg4->Draw("(eta1)>>hbkg4(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto)); //weight also on BR = 0.002 if using the 50ns samples
  TH1F *hbkg4 =(TH1F*)gPad->GetPrimitive("hbkg4");
  tree_bkg5->Draw("(eta1)>>hbkg5(15,-3,3)","weight"*(mggmin && mggmax && genmatch&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg5 =(TH1F*)gPad->GetPrimitive("hbkg5");
  tree_bkg6->Draw("(eta1)>>hbkg6(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg6 =(TH1F*)gPad->GetPrimitive("hbkg6");
  tree_bkg7->Draw("(eta1)>>hbkg7(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg7 =(TH1F*)gPad->GetPrimitive("hbkg7");
  tree_bkg8->Draw("(eta1)>>hbkg8(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg8 =(TH1F*)gPad->GetPrimitive("hbkg8");
  tree_bkg9->Draw("(eta1)>>hbkg9(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg9 =(TH1F*)gPad->GetPrimitive("hbkg9");
  tree_bkg10->Draw("(eta1)>>hbkg10(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg10 =(TH1F*)gPad->GetPrimitive("hbkg10");
  tree_bkg11->Draw("(eta1)>>hbkg11(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg11 =(TH1F*)gPad->GetPrimitive("hbkg11");
  tree_bkg12->Draw("(eta1)>>hbkg12(15,-3,3)","weight"*(mggmin && mggmax&& METCut &&pt1Cut && pt2Cut&& eveto));
  TH1F *hbkg12 =(TH1F*)gPad->GetPrimitive("hbkg12");
  
  hdata->SetMarkerColor(kBlack);
  hdata->SetMarkerStyle(15);
  hdata->SetLineColor(kBlack);
  
  h1->SetLineColor(kRed+3);
  h2->SetLineColor(kRed+1);
  h3->SetLineColor(kRed);
  h4->SetLineColor(kPink+2);
  h5->SetLineColor(kPink+4);
  h6->SetLineColor(kPink+7);
  h7->SetLineColor(kMagenta+2);
 
  h1->SetLineWidth(2);
  h2->SetLineWidth(2);  
  h3->SetLineWidth(2);
  h4->SetLineWidth(2);
  h5->SetLineWidth(2);
 h6->SetLineWidth(2);
 h7->SetLineWidth(2);
  




  THStack *hs= new THStack("hs","");
  hbkg7->SetFillColor(kGreen+2);
  hbkg6->SetFillColor(kGreen);
  hbkg8->SetFillColor(kYellow);
  hbkg4->SetFillColor(kOrange);
  hbkg9->SetFillColor(kOrange+7);
  hbkg10->SetFillColor(kOrange+4);
  hbkg11->SetFillColor(kCyan);
  hbkg12->SetFillColor(kCyan+1);
  hbkg5->SetFillColor(kBlue+2);
  hbkg2->SetFillColor(kBlue);
  hbkg3->SetFillColor(kMagenta-2);
  hbkg1->SetFillColor(kViolet);

  hbkg1->SetLineColor(kBlack);
  hbkg2->SetLineColor(kBlack);
  hbkg3->SetLineColor(kBlack);
  hbkg4->SetLineColor(kBlack);
  hbkg5->SetLineColor(kBlack);
  hbkg6->SetLineColor(kBlack);
  hbkg7->SetLineColor(kBlack);
  hbkg8->SetLineColor(kBlack);
  hbkg9->SetLineColor(kBlack);
  hbkg10->SetLineColor(kBlack);
  hbkg11->SetLineColor(kBlack);
  hbkg12->SetLineColor(kBlack);

  hs->Add(hbkg7);
  hs->Add(hbkg6);
  hs->Add(hbkg8);
  hs->Add(hbkg4);
  hs->Add(hbkg9);
  hs->Add(hbkg10);
  hs->Add(hbkg11);
  hs->Add(hbkg12);
  hs->Add(hbkg2);
  hs->Add(hbkg5);
  hs->Add(hbkg3);
  hs->Add(hbkg1);






  
  TH1F *hsum = (TH1F*)hbkg1->Clone("hsum");
  hsum->Add(hbkg2);
  hsum->Add(hbkg3);
  hsum->Add(hbkg4);
  hsum->Add(hbkg5);
  hsum->Add(hbkg6);
  hsum->Add(hbkg7);
  hsum->Add(hbkg8);
  hsum->Add(hbkg9);
  hsum->Add(hbkg10);
  hsum->Add(hbkg11);
  hsum->Add(hbkg12);

  // hs->SetMaximum(1000000);
 hs->SetMaximum(5000);
  // hs->SetMinimum(0.1);
  hs->SetTitle("");
  hs->Draw("HIST"); 

  hsum->SetMarkerStyle(1);
  hsum->SetFillColor(kGray+3);
  hsum->SetFillStyle(3002);
  hsum->Draw("same e2");
  h2->Draw("same hist");
  h3->Draw("same hist"); 
  h4->Draw("same hist");
  h1->Draw("same hist");
  h5->Draw("same hist"); 
 h6->Draw("same hist"); 
 h7->Draw("same hist"); 

  hdata->Draw("same E1");
  
  hs->GetXaxis()->SetLabelOffset(999);
  hs->GetYaxis()->SetTitle("Events/0.4");  
  hs->GetYaxis()->SetTitleOffset(1.4);  
  gPad->Modified();
  
  leg->AddEntry(hdata,"Data","lep");
     
  
  
  leg->AddEntry(hbkg1,"#gamma #gamma","f");
leg->AddEntry(h1,"m_{Z'} = 600 GeV","l");                                                                               

  leg->AddEntry(hbkg2,"Drell Yann","f");
 
  leg->AddEntry(hbkg3,"#gamma + Jets","f");
leg->AddEntry(h2,"m_{Z'} = 800 GeV","l");                                                                               

  leg->AddEntry(hbkg5,"QCD","f");
  
  leg->AddEntry(hbkg4,"ggH","f");
 leg->AddEntry(h3,"m_{Z'} = 1000 GeV","l");                                                                    
 
  leg->AddEntry(hbkg6,"VH","f");
 
  leg->AddEntry(hbkg7,"ttH","f");

 leg->AddEntry(h4,"m_{Z'} = 1200 GeV","l");                                                                    
  leg->AddEntry(hbkg8,"VBF H","f");
  leg->AddEntry(hbkg9,"t + #gamma + Jets","f");
leg->AddEntry(h5,"m_{Z'} = 1400 GeV","l");                                                            
leg->AddEntry(hbkg10,"tt + #gamma +Jets","f");
  leg->AddEntry(hbkg11,"#gamma+W","f");
leg->AddEntry(h6,"m_{Z'} = 1700 GeV","l");     
  leg->AddEntry(hbkg12,"#gamma+Z","f");
  leg->AddEntry(hsum,"Bkg uncertainty","f");

 leg->AddEntry(h7,"m_{Z'} = 2500 GeV","l");                            
 leg->Draw("same");
  
  c1->cd(); 
  smallPad->Draw(); 
  smallPad->cd();

  TGraphErrors *gr = new TGraphErrors(0);
  double integralData=hdata->Integral();
  double integralBKG=hsum->Integral();
  double error, ratio;
  for(int w=1; w<15; w++){
    if((hdata->GetBinContent(w)!=0) && (hsum->GetBinContent(w)!=0)){
      
      gr->SetPoint(w, hdata->GetBinCenter(w),(hdata->GetBinContent(w))/(hsum->GetBinContent(w)));
      ratio= (hdata->GetBinContent(w))/(hsum->GetBinContent(w));
      error= (hdata->GetBinContent(w)*sqrt(hsum->GetBinContent(w))/(hsum->GetBinContent(w)*hsum->GetBinContent(w)) + sqrt(hdata->GetBinContent(w))/hsum->GetBinContent(w));
      std::cout<<"VALUE: "<<ratio<<" ERROR: "<<error<<std::endl;
      gr->SetPointError(w, hdata->GetBinWidth(w)/2,error);
    }else{
      gr->SetPoint(w, hdata->GetBinCenter(w),10);
    } 
  }

  
  
  gStyle->SetPadTickY(1);
  gStyle->SetPadTickX(1);
  gr->GetHistogram()->SetMaximum(2);
  gr->GetHistogram()->SetMinimum(0.1);
  
  gStyle->SetTextSize(14);
  gROOT->ForceStyle();
  
  gr->GetXaxis()->SetLabelFont(43);
  gr->GetXaxis()->SetLabelSize(15);
  gr->GetYaxis()->SetLabelFont(43);
  gr->GetYaxis()->SetLabelSize(15);
  
  gr->GetXaxis()->SetLimits(-3,3);
  
  
  gPad->SetGrid();
  gStyle->SetStripDecimals(kTRUE);
  gr->SetMarkerStyle(20);
  gr->SetMarkerSize(0.7);
  
  
  gr->Draw("AZP");
  gr->GetXaxis()->SetTitle("#eta_{1}");
  gr->GetXaxis()->SetTitleSize(0.1);
  gr->GetYaxis()->SetTitleSize(0.1);
  gr->GetYaxis()->SetNdivisions(505);
 
  gr->GetXaxis()->SetTitleOffset(1);
  gr->GetYaxis()->SetTitle("Data/MC"); 
  gr->GetYaxis()->SetTitleOffset(0.4);
  gr->SetTitle(""); 
  smallPad->Update();
  TF1* line = new TF1("line","1",-3,3);
  line->SetLineColor(kRed);
  line->SetLineWidth(2);
  line->Draw("L same");
  gr->Draw("ZP SAME");
  

  if(pt1min==0 && pt2min == 0 && METmin == 0){
    c1->SaveAs("./25ns_2246inv_v3/plots/kinematics/eta1.png");
    c1->SaveAs("./25ns_2246inv_v3/plots/kinematics/eta1.pdf");
  }
  if(pt1min==0.65 && pt2min == 0.25){
    c1->SaveAs(Form("./25ns_2246inv_v3/plots/kinematics/eta1_optcuts_MET%.0lf.png",METmin));
    c1->SaveAs(Form("./25ns_2246inv_v3/plots/kinematics/eta1_optcuts_MET%.0lf.pdf",METmin));
  }
  


}
void drawDifference(TH1* iH0,TH1 *iH1,TH1* iH2, TGraphErrors* iH3, int chnl,TGraphErrors* iH4,TGraphAsymmErrors* iH5,TH1* StatErrBand,TGraphErrors* iH6){
  std::string lName = std::string(iH0->GetName());
  TH1F *lHDiff  = new TH1F((lName+"Diff").c_str(),(lName+"Diff").c_str(),nBins-1,WptLogBins);// lHDiff->Sumw2();
  TH1F *lXHDiff1 = new TH1F((lName+"XDiff1").c_str(),(lName+"XDiff1").c_str(),iH0->GetNbinsX(),iH0->GetXaxis()->GetXmin(),iH0->GetXaxis()->GetXmax());
  int i1 = 0;
  lXHDiff1->SetLineWidth(2); lXHDiff1->SetLineColor(kBlack); //lXHDiff1->SetLineStyle(2);
  
  StatErrBand->SetMarkerStyle(kFullCircle); StatErrBand->SetMarkerColor(kBlack);StatErrBand->SetMarkerSize(0.6);
  StatErrBand->SetLineWidth(2); StatErrBand->SetLineColor(kBlack);
  
  lHDiff->GetYaxis()->SetRangeUser(0.5,1.5); //Eleminus
  if(chnl==2)
    lHDiff->GetYaxis()->SetRangeUser(0.5,1.5);//Eleminus
  if(chnl==3)
    lHDiff->GetYaxis()->SetRangeUser(0.5,1.5);
  lHDiff->GetYaxis()->SetTitleOffset(0.4);
  lHDiff->GetYaxis()->SetTitleSize(0.12);
  lHDiff->GetYaxis()->SetLabelSize(0.12);
  lHDiff->GetYaxis()->CenterTitle();
  lHDiff->GetXaxis()->SetTitleOffset(1.0);
  lHDiff->GetXaxis()->SetTitleSize(0.12);
  lHDiff->GetXaxis()->SetLabelSize(0);
  if(chnl==3)
    lHDiff->GetXaxis()->SetLabelSize(0.12);
  lHDiff->GetYaxis()->SetNdivisions(405);
  if(chnl==3)
    lHDiff->GetXaxis()->SetTitle("p_{T}^{W} [GeV]");
  lHDiff->GetYaxis()->SetTitle("Theory/Data");
  gStyle->SetOptStat(0);
  
  for(int i0 = 0; i0 < lHDiff->GetNbinsX()+1; i0++) {
    double lXCenter = lHDiff->GetBinCenter(i0);
    double lXVal     = iH0   ->GetBinContent(i0);
    lXHDiff1->SetBinContent(i0, 1.0);
    while(iH1->GetBinCenter(i1) < lXCenter) {i1++;}
    if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinContent(i0,lXVal/(iH1->GetBinContent(i0)));
    if(iH1->GetBinContent(i0) > 0) lHDiff->SetBinError(i0,0.00001);
  }
  
  TGraphErrors* ErrBand = new TGraphErrors(iH2);
  ErrBand->SetFillColor(kBlack);
  ErrBand->SetFillStyle(3354);
  ErrBand->SetLineWidth(1);
  
  if (chnl == 1)
  {
    lHDiff->SetMarkerStyle(kOpenCircle);
    lHDiff->SetMarkerColor(kBlue);
    lHDiff->SetLineColor(kBlue);
  }
  if (chnl == 2)
  {
    lHDiff->SetMarkerStyle(kOpenTriangleUp);
    lHDiff->SetMarkerColor(kRed);
    lHDiff->SetLineColor(kRed);
  }
  if (chnl == 3)
  {
    lHDiff->SetMarkerStyle(kOpenSquare);
    lHDiff->SetMarkerColor(kGreen+3);
    lHDiff->SetLineColor(kGreen+3);
  }
  
  lHDiff->SetMarkerSize(0.8);


  lHDiff->SetTitle("");
  lHDiff->Draw("E");
  if (chnl == 1)
    iH5->Draw("2same");
  if (chnl == 2 || chnl == 3)
    iH4->Draw("2");
  if (chnl == 3)
    iH6->Draw("2");
  if (chnl == 2 || chnl == 3)
    iH3->Draw("2same");
  lXHDiff1->Draw("histsame");
  ErrBand->Draw("2same");
  lHDiff->Draw("Esame");
  StatErrBand->Draw("E1same");
}
示例#27
0
文件: shapeComp.C 项目: kskovpen/bTag
void shapeComp()
{
   gROOT->SetBatch();
   gROOT->SetStyle("Plain");
   
   gStyle->SetOptStat(0);

   gROOT->ProcessLine("#include <string>");
   gROOT->ProcessLine("#include <TH1F.h>");
   
   gROOT->ProcessLine(".x common.C");
   gROOT->ProcessLine(".x def.C");
   
   gROOT->ProcessLine(".L addbin.C");

   TCanvas *c1 = new TCanvas("c1","c1",0,0,600,500);
   
   gStyle->SetHistTopMargin(0);
   
   TH1F *h_MC_preTag_ljet;
   TH1F *h_MC_postTag_ljet;
   TH1F *h_MC_preTag_bjet;
   TH1F *h_MC_postTag_bjet;
   TH1F *h_MC_preTag_cjet;
   TH1F *h_MC_postTag_cjet;
   TH1F *h_DATA;

   for(int ih=0;ih<nhist;ih++)
     {	
	for(int ipt=0;ipt<nptbin;ipt++)
	  {	
	     std::string varhMC_preTag_ljet = "h_j1_"+hist[ih]+"_ljet_"+ptbin[ipt]+"_nosel_nosel";
	     std::string varhMC_postTag_ljet = "h_j1_"+hist[ih]+"_ljet_"+ptbin[ipt]+"_nosel_" + tag;
	     std::string varhMC_preTag_bjet = "h_j1_"+hist[ih]+"_bjet_"+ptbin[ipt]+"_nosel_nosel";
	     std::string varhMC_postTag_bjet = "h_j1_"+hist[ih]+"_bjet_"+ptbin[ipt]+"_nosel_" + tag;
	     std::string varhMC_preTag_cjet = "h_j1_"+hist[ih]+"_cjet_"+ptbin[ipt]+"_nosel_nosel";
	     std::string varhMC_postTag_cjet = "h_j1_"+hist[ih]+"_cjet_"+ptbin[ipt]+"_nosel_" + tag;
	     std::string varhDATA = "h_j1_"+hist[ih]+"_ajet_"+ptbin[ipt]+"_nosel_UNTAGbc";
	     
	     for(int i=0;i<v_mc_unfilt.size();i++)
	       {
		  std::string fname = fpathMC+v_mc_unfilt.at(i);
		  fbatch_MC_unfilt[i] = TFile::Open(fname.c_str());
		  
		  TH1F *hf_preTag_ljet = (TH1F*)fbatch_MC_unfilt[i]->Get(varhMC_preTag_ljet.c_str());
		  TH1F *hf_postTag_ljet = (TH1F*)fbatch_MC_unfilt[i]->Get(varhMC_postTag_ljet.c_str());

		  if( i == 0 ) 
		    {
		       h_MC_preTag_ljet = (TH1F*)hf_preTag_ljet->Clone("h_MC_preTag_ljet");
		       h_MC_postTag_ljet = (TH1F*)hf_postTag_ljet->Clone("h_MC_postTag_ljet");
		    }	
		  else 
		    {
		       h_MC_preTag_ljet->Add(hf_preTag_ljet);
		       h_MC_postTag_ljet->Add(hf_postTag_ljet);
		    }   
	       }

	     for(int i=0;i<v_mc_filt.size();i++)
	       {
		  std::string fname = fpathMC+v_mc_filt.at(i);
		  fbatch_MC_filt[i] = TFile::Open(fname.c_str());
		  
		  TH1F *hf_preTag_bjet = (TH1F*)fbatch_MC_filt[i]->Get(varhMC_preTag_bjet.c_str());
		  TH1F *hf_postTag_bjet = (TH1F*)fbatch_MC_filt[i]->Get(varhMC_postTag_bjet.c_str());

		  TH1F *hf_preTag_cjet = (TH1F*)fbatch_MC_filt[i]->Get(varhMC_preTag_cjet.c_str());
		  TH1F *hf_postTag_cjet = (TH1F*)fbatch_MC_filt[i]->Get(varhMC_postTag_cjet.c_str());
		  
		  if( i == 0 ) 
		    {
		       h_MC_preTag_bjet = (TH1F*)hf_preTag_bjet->Clone("h_MC_preTag_bjet");
		       h_MC_postTag_bjet = (TH1F*)hf_postTag_bjet->Clone("h_MC_postTag_bjet");

		       h_MC_preTag_cjet = (TH1F*)hf_preTag_cjet->Clone("h_MC_preTag_cjet");
		       h_MC_postTag_cjet = (TH1F*)hf_postTag_cjet->Clone("h_MC_postTag_cjet");
		    }	
		  else 
		    {
		       h_MC_preTag_bjet->Add(hf_preTag_bjet);
		       h_MC_postTag_bjet->Add(hf_postTag_bjet);

		       h_MC_preTag_cjet->Add(hf_preTag_cjet);
		       h_MC_postTag_cjet->Add(hf_postTag_cjet);
		    }   
	       }
	     
	     for(int i=0;i<v_data.size();i++)
	       {
		  std::string fname = fpathDATA+v_data.at(i);
		  fbatch_DATA[i] = TFile::Open(fname.c_str());
		  
		  TH1F *hf = (TH1F*)fbatch_DATA[i]->Get(varhDATA.c_str());

		  if( i == 0 ) 
		    {
		       h_DATA = (TH1F*)hf->Clone("h_DATA");
		    }	
		  else 
		    {
		       h_DATA->Add(hf);
		    }   
	       }
	     
	     addbin(h_MC_preTag_ljet);
	     addbin(h_MC_postTag_ljet);
	     addbin(h_MC_preTag_bjet);
	     addbin(h_MC_postTag_bjet);
	     addbin(h_MC_preTag_cjet);
	     addbin(h_MC_postTag_cjet);
	     addbin(h_DATA);
	     
	     h_MC_preTag_ljet = (TH1F*)h_MC_preTag_ljet->Rebin(nbm1d,"");
	     h_MC_postTag_ljet = (TH1F*)h_MC_postTag_ljet->Rebin(nbm1d,"");
	     h_MC_preTag_bjet = (TH1F*)h_MC_preTag_bjet->Rebin(nbm1d,"");
	     h_MC_postTag_bjet = (TH1F*)h_MC_postTag_bjet->Rebin(nbm1d,"");
	     h_MC_preTag_cjet = (TH1F*)h_MC_preTag_cjet->Rebin(nbm1d,"");
	     h_MC_postTag_cjet = (TH1F*)h_MC_postTag_cjet->Rebin(nbm1d,"");
	     h_DATA = (TH1F*)h_DATA->Rebin(nbm1d,"");

	     if( h_MC_preTag_ljet->Integral() ) h_MC_preTag_ljet->Scale(1./h_MC_preTag_ljet->Integral());
	     if( h_MC_postTag_ljet->Integral() ) h_MC_postTag_ljet->Scale(1./h_MC_postTag_ljet->Integral());
	     if( h_MC_preTag_bjet->Integral() ) h_MC_preTag_bjet->Scale(1./h_MC_preTag_bjet->Integral());
	     if( h_MC_postTag_bjet->Integral() ) h_MC_postTag_bjet->Scale(1./h_MC_postTag_bjet->Integral());
	     if( h_MC_preTag_cjet->Integral() ) h_MC_preTag_cjet->Scale(1./h_MC_preTag_cjet->Integral());
	     if( h_MC_postTag_cjet->Integral() ) h_MC_postTag_cjet->Scale(1./h_MC_postTag_cjet->Integral());
	     if( h_DATA->Integral() ) h_DATA->Scale(1./h_DATA->Integral());

	     h_MC_preTag_ljet->GetXaxis()->SetTitle(xtit[ih].c_str());
	     h_MC_preTag_bjet->GetXaxis()->SetTitle(xtit[ih].c_str());
	     h_MC_preTag_cjet->GetXaxis()->SetTitle(xtit[ih].c_str());
	     
	     h_MC_preTag_ljet->SetLineColor(kRed);
	     h_MC_preTag_ljet->SetMarkerColor(kRed);
	     h_MC_preTag_bjet->SetLineColor(kRed);
	     h_MC_preTag_bjet->SetMarkerColor(kRed);
	     h_MC_preTag_cjet->SetLineColor(kRed);
	     h_MC_preTag_cjet->SetMarkerColor(kRed);
	     h_MC_postTag_ljet->SetLineColor(kBlue);
	     h_MC_postTag_ljet->SetMarkerColor(kBlue);
	     h_MC_postTag_bjet->SetLineColor(kBlue);
	     h_MC_postTag_bjet->SetMarkerColor(kBlue);
	     h_MC_postTag_cjet->SetLineColor(kBlue);
	     h_MC_postTag_cjet->SetMarkerColor(kBlue);
	     h_DATA->SetLineColor(kBlack);
	     h_DATA->SetMarkerColor(kBlack);

	     TLegend *leg = new TLegend(0.65,0.90,0.88,0.75);
	     leg->SetFillColor(253);
	     leg->SetBorderSize(0);
	     leg->AddEntry(h_DATA,"Data","f");
	     leg->AddEntry(h_MC_preTag_ljet,"pre-Tag MC","f");
	     
	     float m_MC_preTag_ljet = h_MC_preTag_ljet->GetMaximum();
	     float m_DATA = h_DATA->GetMaximum();
	     float max = (m_MC_preTag_ljet > m_DATA) ? m_MC_preTag_ljet : m_DATA;

	     h_MC_preTag_ljet->SetMaximum(1.4*max);
	     
	     h_MC_preTag_ljet->Draw("hist e1");
	     h_DATA->Draw("hist e1 same");
	     leg->Draw();	     
	     std::string fsave = "pics/"+hist[ih]+"_"+ptbin[ipt]+"_ljet.eps";
	     c1->Print(fsave.c_str());
	     leg->Clear();
	     c1->Clear();
	     
	     leg->AddEntry(h_MC_postTag_bjet,"post-Tag MC","f");
	     leg->AddEntry(h_MC_preTag_bjet,"pre-Tag MC","f");
	     
	     float m_MC_preTag_bjet = h_MC_preTag_bjet->GetMaximum();
	     float m_MC_postTag_bjet = h_MC_postTag_bjet->GetMaximum();
	     float max_bjet = (m_MC_preTag_bjet > m_MC_postTag_bjet) ? m_MC_preTag_bjet : m_MC_postTag_bjet;

	     h_MC_preTag_bjet->SetMaximum(1.4*max_bjet);
	     
	     h_MC_preTag_bjet->Draw("hist e1");
	     h_MC_postTag_bjet->Draw("hist e1 same");
	     leg->Draw();	     
	     std::string fsave = "pics/"+hist[ih]+"_"+ptbin[ipt]+"_bjet.eps";
	     c1->Print(fsave.c_str());
	     leg->Clear();
	     c1->Clear();	     

	     leg->AddEntry(h_MC_postTag_cjet,"post-Tag MC","f");
	     leg->AddEntry(h_MC_preTag_cjet,"pre-Tag MC","f");
	     
	     float m_MC_preTag_cjet = h_MC_preTag_cjet->GetMaximum();
	     float m_MC_postTag_cjet = h_MC_postTag_cjet->GetMaximum();
	     float max_cjet = (m_MC_preTag_cjet > m_MC_postTag_cjet) ? m_MC_preTag_cjet : m_MC_postTag_cjet;

	     h_MC_preTag_cjet->SetMaximum(1.4*max_cjet);
	     
	     h_MC_preTag_cjet->Draw("hist e1");
	     h_MC_postTag_cjet->Draw("hist e1 same");
	     leg->Draw();	     
	     std::string fsave = "pics/"+hist[ih]+"_"+ptbin[ipt]+"_cjet.eps";
	     c1->Print(fsave.c_str());
	     leg->Clear();
	     c1->Clear();	     
	     
	     delete leg;
	  }
     }   
   
   gApplication->Terminate();
}
示例#28
0
void MCJetIDskimTree(){
    TH1F * jetpt;
    TH1F * jetpt_real;
    TH1F * jetpt_fake;
    TH2F * jetptchMaxpt;      //Added
    TH2F * jetptchMax;    //Added
    TH2F * jetptneuMaxpt;     //Added
    TH2F * jetptneuMaxr;   //Added
    TH2F * jetptneuMax;       //Added
    TH2F * jetptphoMaxpt; //Added 
    TH2F * jetptphoMax;   //Added
    TH2F * jetptchSum;    //Added
    TH2F * jetptneuSum;    //Added
    TH2F * jetptphoSum;    //Added
    TH2F * jetptchSumpt;    //Added
    TH2F * jetptneuSumpt;    //Added
    TH2F * jetptphoSumpt;    //Added
    TH2F * jetptchN;       //Added
    TH2F * jetptneuN;      //Added
    TH2F * jetptphoN;      //Added
    TH2F * jetptSumSum;   //Added
    TH2F * jetptSumSumrawpt;   //Added
    TH2F * jetptSumSumpt;   //Added

    TH2F * jetptchMaxpt_real;	//Added
    TH2F * jetptchMaxpt_fake;	//Added
    TH2F * jetptchMax_real;	//Added
    TH2F * jetptchMax_fake;	//Added
    TH2F * jetptneuMaxpt_real;	//Added
    TH2F * jetptneuMaxpt_fake;	//Added
    TH2F * jetptneuMaxr_fake;      //Added
    TH2F * jetptneuMaxr_real;      //Added
    TH2F * jetptneuMax_fake;	//Added
    TH2F * jetptneuMax_real;	//Added
    TH2F * jetptphoMaxpt_fake;    //Added
    TH2F * jetptphoMaxpt_real;    //Added
    TH2F * jetptphoMax_fake;      //Added
    TH2F * jetptphoMax_real;      //Added
    TH2F * jetptchSum_fake;	//Added
    TH2F * jetptchSum_real;	//Added
    TH2F * jetptneuSum_fake;       //Added
    TH2F * jetptneuSum_real;       //Added
    TH2F * jetptphoSum_fake;       //Added
    TH2F * jetptphoSum_real;       //Added
    TH2F * jetptchSumpt_fake;       //Added
    TH2F * jetptchSumpt_real;       //Added
    TH2F * jetptneuSumpt_fake;       //Added
    TH2F * jetptneuSumpt_real;       //Added
    TH2F * jetptphoSumpt_fake;       //Added
    TH2F * jetptphoSumpt_real;       //Added
    TH2F* jetptchN_fake;	
    TH2F* jetptchN_real;
    TH2F* jetptneuN_fake;
    TH2F* jetptneuN_real;
    TH2F* jetptphoN_fake;
    TH2F* jetptphoN_real;
    TH2F * jetptSumSum_fake;	//Added
    TH2F * jetptSumSum_real;	//Added
    TH2F * jetptSumSumrawpt_fake;      //Added
    TH2F * jetptSumSumrawpt_real;      //Added
    TH2F * jetptSumSumpt_fake;      //Added
    TH2F * jetptSumSumpt_real;      //Added

TH1F * jetptEtaBin[7];
TH1F * jetptEtaBin_real[7];
TH1F * jetptEtaBin_fake[7];
TH2F * jetptchMaxEtaBin[7];	//Added
TH2F * jetptchMaxEtaBin_fake[7];	//Added
TH2F * jetptchMaxEtaBin_real[7];	//Added
TH2F * jetptchMaxptEtaBin[7];	//Added
TH2F * jetptchMaxptEtaBin_fake[7];	//Added
TH2F * jetptchMaxptEtaBin_real[7];	//Added
TH2F * jetptneuMaxptEtaBin[7];	//Added
TH2F * jetptneuMaxrEtaBin[7];	//Added
TH2F * jetptneuMaxrEtaBin_fake[7];	//Added
TH2F * jetptneuMaxrEtaBin_real[7];	//Added
TH2F * jetptphoMaxptEtaBin[7];	//Added
TH2F * jetptchSumptEtaBin[7];	//Added
TH2F * jetptneuSumptEtaBin[7];	//Added
TH2F * jetptphoSumptEtaBin[7];	//Added
TH2F * jetptSumSumptEtaBin[7];	//Added
TH2F * jetptSumSumptEtaBin_fake[7];	//Added
TH2F * jetptSumSumptEtaBin_real[7];	//Added
TH2F * jetptSumSumrawptEtaBin[7];		//Added

    jetpt = new TH1F(Form("jetptEtaBin-10_10"), Form("jetptEtaBin-10_10"), 1000, 0., 1000.);       //Added
    jetpt->Sumw2(); 
    jetpt_real = new TH1F(Form("jetptEtaBin_real-10_10"), Form("jetptEtaBin_real-10_10"), 1000, 0., 1000.);       //Added
    jetpt_real->Sumw2(); 
    jetpt_fake = new TH1F(Form("jetptEtaBin_fake-10_10"), Form("jetptEtaBin_fake-10_10"), 1000, 0., 1000.);       //Added
    jetpt_fake->Sumw2(); 

    jetptchMax = new TH2F(Form("jetptchMaxEtaBin-10_10"), Form("jetptchMaxEtaBin-10_10"), 1000, 0., 1000., 3000, 0., 300.);       //Added
        jetptchMax->Sumw2();      //Added

        jetptchMaxpt = new TH2F(Form("jetptchMaxptEtaBin-10_10"), Form("jetptchMaxptEtaBin-10_10"), 1000, 0., 1000., 200, 0., 2.);    //Added
    jetptchMaxpt->Sumw2();      //Added

        jetptneuMaxpt = new TH2F(Form("jetptneuMaxptEtaBin-10_10"), Form("jetptneuMaxptEtaBin-10_10"), 1000, 0., 1000., 200, 0., 2.);    //Added
    jetptneuMaxpt->Sumw2();      //Added

        jetptneuMax = new TH2F(Form("jetptneuMaxEtaBin-10_10"), Form("jetptneuMaxEtaBin-10_10"), 1000, 0., 1000., 3000, 0., 300.);    //Added
    jetptneuMax->Sumw2();      //Added

        jetptneuMaxr = new TH2F(Form("jetptneuMaxrEtaBin-10_10"), Form("jetptneuMaxrEtaBin-10_10"), 1000, 0., 1000., 1000, 0., 5.);    //Added
        jetptneuMaxr->Sumw2();      //Added

       jetptphoMaxpt = new TH2F(Form("jetptphoMaxptEtaBin-10_10"), Form("jetptphoMaxptEtaBin-10_10"), 1000, 0., 1000., 200, 0., 2.);    //Added
        jetptphoMaxpt->Sumw2();      //Added

        jetptphoMax = new TH2F(Form("jetptphoMaxEtaBin-10_10"), Form("jetptphoMaxEtaBin-10_10"), 1000, 0., 1000., 3000, 0., 300.);    //Added
        jetptphoMax->Sumw2();      //Added

        jetptchSum = new TH2F(Form("jetptchSumEtaBin-10_10"), Form("jetptchSumEtaBin-10_10"), 1000, 0., 1000., 3000, 0., 300.);    //Added
        jetptchSum->Sumw2();      //Added

        jetptneuSum = new TH2F(Form("jetptneuSumEtaBin-10_10"), Form("jetptneuSumEtaBin-10_10"), 1000, 0., 1000., 3000, 0., 300.);    //Added
        jetptneuSum->Sumw2();      //Added

        jetptphoSum = new TH2F(Form("jetptphoSumEtaBin-10_10"), Form("jetptphoSumEtaBin-10_10"), 1000, 0., 1000., 3000, 0., 300.);    //Added
        jetptphoSum->Sumw2();      //Added

        jetptchSumpt = new TH2F(Form("jetptchSumptEtaBin-10_10"), Form("jetptchSumptEtaBin-10_10"), 1000, 0., 1000., 200, 0., 2.);    //Added
        jetptchSumpt->Sumw2();      //Added

        jetptneuSumpt = new TH2F(Form("jetptneuSumptEtaBin-10_10"), Form("jetptneuSumptEtaBin-10_10"), 1000, 0., 1000., 200, 0., 2.);    //Added
        jetptneuSumpt->Sumw2();      //Added

        jetptphoSumpt = new TH2F(Form("jetptphoSumptEtaBin-10_10"), Form("jetptphoSumptEtaBin-10_10"), 1000, 0., 1000., 200, 0., 2.);    //Added
        jetptphoSumpt->Sumw2();      //Added

        jetptchN = new TH2F(Form("jetptchNEtaBin-10_10"), Form("jetptchNEtaBin-10_10"),1000,0., 1000., 100, 0, 100);
        jetptchN->Sumw2();

        jetptneuN = new TH2F(Form("jetptneuNEtaBin-10_10"), Form("jetptneuNEtaBin-10_10"),1000,0., 1000., 100, 0, 100);
        jetptneuN->Sumw2();

        jetptphoN = new TH2F(Form("jetptphoNEtaBin-10_10"), Form("jetptphoNEtaBin-10_10"),1000,0., 1000., 100, 0, 100);
        jetptphoN->Sumw2();

        jetptSumSum = new TH2F(Form("jetptSumSumEtaBin-10_10"), Form("jetptSumSumEtaBin-10_10"), 1000, 0., 1000., 1000, 0., 1000);    //Added
        jetptSumSum->Sumw2();      //Added

        jetptSumSumrawpt = new TH2F(Form("jetptSumSumrawptEtaBin-10_10"), Form("jetptSumSumrawptEtaBin-10_10"), 1000, 0., 1000., 2000, 0., 10);    //Added
        jetptSumSumrawpt->Sumw2();      //Added
        jetptSumSumpt = new TH2F(Form("jetptSumSumptEtaBin-10_10"), Form("jetptSumSumptEtaBin-10_10"), 1000, 0., 1000., 2000, 0., 10);    //Added
        jetptSumSumpt->Sumw2();      //Added
		
	jetptchMax_real = new TH2F(Form("jetptchMaxEtaBin_real-10_10"), Form("jetptchMaxEtaBin_real-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptchMax_real->Sumw2();      //Added

        jetptchMax_fake = new TH2F(Form("jetptchMaxEtaBin_fake-10_10"), Form("jetptchMaxEtaBin_fake-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptchMax_fake->Sumw2();      //Added
	

	jetptchMaxpt_real = new TH2F(Form("jetptchMaxptEtaBin_real-10_10"), Form("jetptchMaxptEtaBin_real-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptchMaxpt_real->Sumw2();      //Added

        jetptchMaxpt_fake = new TH2F(Form("jetptchMaxptEtaBin_fake-10_10"), Form("jetptchMaxptEtaBin_fake-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptchMaxpt_fake->Sumw2();      //Added	

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

        jetptneuMaxpt_real = new TH2F(Form("jetptneuMaxptEtaBin_real-10_10"), Form("jetptneuMaxptEtaBin_real-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptneuMaxpt_real->Sumw2();      //Added

        jetptneuMaxpt_fake = new TH2F(Form("jetptneuMaxptEtaBin_fake-10_10"), Form("jetptneuMaxptEtaBin_fake-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptneuMaxpt_fake->Sumw2();      //Added  



        jetptneuMax_real = new TH2F(Form("jetptneuMaxEtaBin_real-10_10"), Form("jetptneuMaxEtaBin_real-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptneuMax_real->Sumw2();      //Added

        jetptneuMax_fake = new TH2F(Form("jetptneuMaxEtaBin_fake-10_10"), Form("jetptneuMaxEtaBin_fake-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptneuMax_fake->Sumw2();      //Added  



        jetptneuMaxr_real = new TH2F(Form("jetptneuMaxrEtaBin_real-10_10"), Form("jetptneuMaxrEtaBin_real-10_10"), 1000, 0., 1000., 1000, 0., 5.);        //Added
        jetptneuMaxr_real->Sumw2();      //Added

		jetptneuMaxr_fake = new TH2F(Form("jetptneuMaxrEtaBin_fake-10_10"), Form("jetptneuMaxrEtaBin_fake-10_10"), 1000, 0., 1000., 1000, 0., 5.);     //Added
        jetptneuMaxr_fake->Sumw2();      //Added

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

        jetptphoMaxpt_real = new TH2F(Form("jetptphoMaxptEtaBin_real-10_10"), Form("jetptphoMaxptEtaBin_real-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptphoMaxpt_real->Sumw2();      //Added

        jetptphoMaxpt_fake = new TH2F(Form("jetptphoMaxptEtaBin_fake-10_10"), Form("jetptphoMaxptEtaBin_fake-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptphoMaxpt_fake->Sumw2();      //Added  



        jetptphoMax_real = new TH2F(Form("jetptphoMaxEtaBin_real-10_10"), Form("jetptphoMaxEtaBin_real-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptphoMax_real->Sumw2();      //Added

        jetptphoMax_fake = new TH2F(Form("jetptphoMaxEtaBin_fake-10_10"), Form("jetptphoMaxEtaBin_fake-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptphoMax_fake->Sumw2();      //Added  

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

        jetptchSum_real = new TH2F(Form("jetptchSumEtaBin_real-10_10"), Form("jetptchSumEtaBin_real-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptchSum_real->Sumw2();      //Added

        jetptchSum_fake = new TH2F(Form("jetptchSumEtaBin_fake-10_10"), Form("jetptchSumEtaBin_fake-10_10"), 1000, 0., 1000., 3000, 0., 300.);      //Added
        jetptchSum_fake->Sumw2();      //Added

        jetptneuSum_real = new TH2F(Form("jetptneuSumEtaBin_real-10_10"), Form("jetptneuSumEtaBin_real-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptneuSum_real->Sumw2();      //Added

        jetptneuSum_fake = new TH2F(Form("jetptneuSumEtaBin_fake-10_10"), Form("jetptneuSumEtaBin_fake-10_10"), 1000, 0., 1000., 3000, 0., 300.);      //Added
        jetptneuSum_fake->Sumw2();      //Added


        jetptphoSum_real = new TH2F(Form("jetptphoSumEtaBin_real-10_10"), Form("jetptphoSumEtaBin_real-10_10"), 1000, 0., 1000., 3000, 0., 300.);        //Added
        jetptphoSum_real->Sumw2();      //Added

        jetptphoSum_fake = new TH2F(Form("jetptphoSumEtaBin_fake-10_10"), Form("jetptphoSumEtaBin_fake-10_10"), 1000, 0., 1000., 3000, 0., 300.);      //Added
        jetptphoSum_fake->Sumw2();      //Added

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

        jetptchSumpt_real = new TH2F(Form("jetptchSumptEtaBin_real-10_10"), Form("jetptchSumptEtaBin_real-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptchSumpt_real->Sumw2();      //Added

        jetptchSumpt_fake = new TH2F(Form("jetptchSumptEtaBin_fake-10_10"), Form("jetptchSumptEtaBin_fake-10_10"), 1000, 0., 1000., 200, 0., 2.);      //Added
        jetptchSumpt_fake->Sumw2();      //Added


        jetptneuSumpt_real = new TH2F(Form("jetptneuSumptEtaBin_real-10_10"), Form("jetptneuSumptEtaBin_real-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptneuSumpt_real->Sumw2();      //Added

        jetptneuSumpt_fake = new TH2F(Form("jetptneuSumptEtaBin_fake-10_10"), Form("jetptneuSumptEtaBin_fake-10_10"), 1000, 0., 1000., 200, 0., 2.);      //Added
        jetptneuSumpt_fake->Sumw2();      //Added


        jetptphoSumpt_real = new TH2F(Form("jetptphoSumptEtaBin_real-10_10"), Form("jetptphoSumptEtaBin_real-10_10"), 1000, 0., 1000., 200, 0., 2.);        //Added
        jetptphoSumpt_real->Sumw2();      //Added

        jetptphoSumpt_fake = new TH2F(Form("jetptphoSumptEtaBin_fake-10_10"), Form("jetptphoSumptEtaBin_fake-10_10"), 1000, 0., 1000., 200, 0., 2.);      //Added
        jetptphoSumpt_fake->Sumw2();      //Added

//--------------------------------------------------------------------------------------------------------
	
	jetptchN_fake = new TH2F(Form("jetptchNEtaBin_fake-10_10"), Form("jetptchNEtaBin_fake-10_10"),1000,0., 1000., 100, 0, 100);
        jetptchN_fake->Sumw2();
	
	jetptchN_real = new TH2F(Form("jetptchNEtaBin_real-10_10"), Form("jetptchNEtaBin_real-10_10"),1000,0., 1000., 100, 0, 100);
        jetptchN_real->Sumw2();

	jetptneuN_fake = new TH2F(Form("jetptneuNEtaBin_fake-10_10"), Form("jetptneuNEtaBin_fake-10_10"),1000,0., 1000., 100, 0, 100);
        jetptneuN_fake->Sumw2();

	jetptneuN_real = new TH2F(Form("jetptneuNEtaBin_real-10_10"), Form("jetptneuNEtaBin_real-10_10"),1000,0., 1000., 100, 0, 100);
        jetptneuN_real->Sumw2();

	jetptphoN_fake = new TH2F(Form("jetptphoNEtaBin_fake-10_10"), Form("jetptphoNEtaBin_fake-10_10"),1000,0., 1000., 100, 0, 100);
        jetptphoN_fake->Sumw2();

	jetptphoN_real = new TH2F(Form("jetptphoNEtaBin_real-10_10"), Form("jetptphoNEtaBin_real-10_10"),1000,0., 1000., 100, 0, 100);
        jetptphoN_real->Sumw2();

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

        jetptSumSum_real = new TH2F(Form("jetptSumSumEtaBin_real-10_10"), Form("jetptSumSumEtaBin_real-10_10"), 1000, 0., 1000., 1000, 0., 1000);        //Added
        jetptSumSum_real->Sumw2();      //Added

        jetptSumSum_fake = new TH2F(Form("jetptSumSumEtaBin_fake-10_10"), Form("jetptSumSumEtaBin_fake-10_10"), 1000, 0., 1000., 1000, 0., 1000);      //Added
        jetptSumSum_fake->Sumw2();      //Added

        jetptSumSumrawpt_real = new TH2F(Form("jetptSumSumrawptEtaBin_real-10_10"), Form("jetptSumSumrawptEtaBin_real-10_10"), 1000, 0., 1000., 2000, 0., 10);        //Added
        jetptSumSumrawpt_real->Sumw2();      //Added

        jetptSumSumrawpt_fake = new TH2F(Form("jetptSumSumrawptEtaBin_fake-10_10"), Form("jetptSumSumrawptEtaBin_fake-10_10"), 1000, 0., 1000., 2000, 0., 10);      //Added
        jetptSumSumrawpt_fake->Sumw2();      //Added	
       
		jetptSumSumpt_real = new TH2F(Form("jetptSumSumptEtaBin_real-10_10"), Form("jetptSumSumptEtaBin_real-10_10"), 1000, 0., 1000., 2000, 0., 10);        //Added
        jetptSumSumpt_real->Sumw2();      //Added

        jetptSumSumpt_fake = new TH2F(Form("jetptSumSumptEtaBin_fake-10_10"), Form("jetptSumSumptEtaBin_fake-10_10"), 1000, 0., 1000., 2000, 0., 10);      //Added
        jetptSumSumpt_fake->Sumw2();      //Added

    for(int ieta=0; ieta < netabin; ieta++){

	jetptEtaBin[ieta] = new TH1F(Form("jetptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000.);    //Added
        jetptEtaBin[ieta]->Sumw2();      //Added
	jetptEtaBin_real[ieta] = new TH1F(Form("jetptEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000.);    //Added
        jetptEtaBin_real[ieta]->Sumw2();      //Added
	jetptEtaBin_fake[ieta] = new TH1F(Form("jetptEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000.);    //Added
        jetptEtaBin_fake[ieta]->Sumw2();      //Added
	jetptchMaxEtaBin[ieta] = new TH2F(Form("jetptchMaxEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptchMaxEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 3000, 0., 300.);    //Added
        jetptchMaxEtaBin[ieta]->Sumw2();      //Added
	jetptchMaxEtaBin_fake[ieta] = new TH2F(Form("jetptchMaxEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptchMaxEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 3000, 0., 300.);    //Added
        jetptchMaxEtaBin_fake[ieta]->Sumw2();      //Added
	jetptchMaxEtaBin_real[ieta] = new TH2F(Form("jetptchMaxEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptchMaxEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 3000, 0., 300.);    //Added
        jetptchMaxEtaBin_real[ieta]->Sumw2();      //Added
	jetptchMaxptEtaBin[ieta] = new TH2F(Form("jetptchMaxptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptchMaxptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 200, 0., 1);    //Added
        jetptchMaxptEtaBin[ieta]->Sumw2();      //Added
	jetptchMaxptEtaBin_fake[ieta] = new TH2F(Form("jetptchMaxptEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptchMaxptEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 200, 0., 1);    //Added
        jetptchMaxptEtaBin_fake[ieta]->Sumw2();      //Added
	jetptchMaxptEtaBin_real[ieta] = new TH2F(Form("jetptchMaxptEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptchMaxptEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 200, 0., 1);    //Added
        jetptchMaxptEtaBin_real[ieta]->Sumw2();      //Added
        jetptphoMaxptEtaBin[ieta] = new TH2F(Form("jetptphoMaxptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptphoMaxptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 200, 0., 1);    //Added
        jetptphoMaxptEtaBin[ieta]->Sumw2();      //Added
        jetptneuMaxptEtaBin[ieta] = new TH2F(Form("jetptneuMaxptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptneuMaxptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 200, 0., 1);    //Added
        jetptneuMaxptEtaBin[ieta]->Sumw2();      //Added
        jetptchSumptEtaBin[ieta] = new TH2F(Form("jetptchSumptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptchSumptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 200, 0., 1);    //Added
        jetptchSumptEtaBin[ieta]->Sumw2();      //Added
        jetptneuSumptEtaBin[ieta] = new TH2F(Form("jetptneuSumptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptneuSumptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 200, 0., 1);    //Added
        jetptneuSumptEtaBin[ieta]->Sumw2();      //Added
        jetptphoSumptEtaBin[ieta] = new TH2F(Form("jetptphoSumptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptphoSumptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 200, 0., 1);    //Added
        jetptphoSumptEtaBin[ieta]->Sumw2();      //Added
        jetptSumSumptEtaBin[ieta] = new TH2F(Form("jetptSumSumptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptSumSumptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 2000, 0., 10.);    //Added
        jetptSumSumptEtaBin[ieta]->Sumw2();        
        jetptSumSumptEtaBin_fake[ieta] = new TH2F(Form("jetptSumSumptEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptSumSumptEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 2000, 0., 10.);    //Added
        jetptSumSumptEtaBin_fake[ieta]->Sumw2();        
        jetptSumSumptEtaBin_real[ieta] = new TH2F(Form("jetptSumSumptEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptSumSumptEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 2000, 0., 10.);    //Added
        jetptSumSumptEtaBin_real[ieta]->Sumw2();        
	jetptSumSumrawptEtaBin[ieta] = new TH2F(Form("jetptSumSumrawptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptSumSumrawptEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 2000, 0., 10.);    //Added
        jetptSumSumrawptEtaBin[ieta]->Sumw2();
	jetptneuMaxrEtaBin[ieta] = new TH2F(Form("jetptneuMaxrEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptneuMaxrEtaBin%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 1000, 0., 5.);    //Added
        jetptneuMaxrEtaBin[ieta]->Sumw2();
	jetptneuMaxrEtaBin_fake[ieta] = new TH2F(Form("jetptneuMaxrEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptneuMaxrEtaBin_fake%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 1000, 0., 5.);    //Added
        jetptneuMaxrEtaBin_fake[ieta]->Sumw2();
	jetptneuMaxrEtaBin_real[ieta] = new TH2F(Form("jetptneuMaxrEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), Form("jetptneuMaxrEtaBin_real%.f_%.f",deta[ieta]*10,deta[ieta+1]*10), 1000, 0., 1000., 1000, 0., 5.);    //Added
        jetptneuMaxrEtaBin_real[ieta]->Sumw2();

      }

  std::cout<<"start working\n";

  cout<<"Analyzing MC!"<<endl;

if(coll=="PPb")
  TFile *f = new TFile("/home/xuq/Documents/HI/RpA/output/skimTree/MCPPbakPu3PFskimfile0_8.root");  
else if(coll=="PP")  
  TFile *f = new TFile("/home/xuq/Documents/HI/RpA/output/skimTree/MCPPakPu3PFskimfile0_9.root");  
else if(coll=="PbP")  
  TFile *f = new TFile("/home/xuq/Documents/HI/RpA/output/skimTree/MCPbPakPu3PFskimfile0_8.root");  

  TTree *nt = (TTree*)f->Get("nt");

  Float_t jtpt[100],jteta[100],rawpt[100],refpt[100],;
	Int_t t_chargedN[100], t_neutralN[100], t_photonN[100];
Float_t t_chargedSum[100], t_photonSum[100], t_neutralSum[100], t_chargedMax[100], t_neutralMax[100], t_photonMax[100], t_eSum[100], t_muSum[100];
Int_t nref, subid[100];
  Float_t xSecWeight,weight,vz;

  nt->SetBranchAddress("vz",&vz);
  nt->SetBranchAddress("nref",&nref);
  nt->SetBranchAddress("rawpt",rawpt);
  nt->SetBranchAddress("jtpt",jtpt);
  nt->SetBranchAddress("refpt",refpt);
  nt->SetBranchAddress("jteta",jteta);
  nt->SetBranchAddress("subid",subid);
    nt->SetBranchAddress("chargedN",t_chargedN);
    nt->SetBranchAddress("photonN",t_photonN);
    nt->SetBranchAddress("neutralN",t_neutralN);
    nt->SetBranchAddress("chargedMax",t_chargedMax);
    nt->SetBranchAddress("photonMax",t_photonMax);
    nt->SetBranchAddress("neutralMax",t_neutralMax);
    nt->SetBranchAddress("chargedSum",t_chargedSum);
    nt->SetBranchAddress("photonSum",t_photonSum);
    nt->SetBranchAddress("neutralSum",t_neutralSum);
    nt->SetBranchAddress("muSum",t_muSum);
    nt->SetBranchAddress("eSum",t_eSum);
    nt->SetBranchAddress("xSecWeight",&xSecWeight);
    nt->SetBranchAddress("weight",&weight);

  Int_t nentries = nt->GetEntries();
 
  for(int i=0; i<nentries; i++){
    nt->GetEntry(i);
	if(TMath::Abs(vz)>15) continue;
        
    if(i%10000==1)    cout<<"analyzing "<< i <<" th event"<<endl;  
for(int j4i = 0; j4i < nref; j4i++){
    double jet_pt = jtpt[j4i];
    double ref_pt = refpt[j4i];
    double jet_eta = jteta[j4i];  
    int sub_id = subid[j4i];  
    double raw_pt = rawpt[j4i];

		double chargedMax = t_chargedMax[j4i];
		double chargedSum = t_chargedSum[j4i];
		double neutralMax = t_neutralMax[j4i];
		double neutralSum = t_neutralSum[j4i];
		double photonMax = t_photonMax[j4i];
		double photonSum = t_photonSum[j4i];
		int chargedN = t_chargedN[j4i];
		int neutralN = t_neutralN[j4i];
		int photonN = t_photonN[j4i];
		double muSum = t_muSum[j4i];
		double eSum = t_eSum[j4i];
	 if(raw_pt<22) continue;
      int dEtaBin = -1;
	if(coll=="PPb")	jet_eta=jet_eta+0.465;
	if(coll=="PbP")	jet_eta=jet_eta-0.465;
	if(wtype=="xSec") weight = xSecWeight;
     if(TMath::Abs(jet_eta)<=1.) {
	  jetpt->Fill(jet_pt,weight);
	  jetptchMax->Fill(jet_pt, chargedMax, weight);  //Added
    	  jetptneuMax->Fill(jet_pt, neutralMax, weight);
    	  jetptphoMax->Fill(jet_pt, photonMax, weight);
    	  jetptchMaxpt->Fill(jet_pt, chargedMax/jet_pt, weight);
    	  jetptneuMaxpt->Fill(jet_pt, neutralMax/jet_pt, weight);
    	  jetptphoMaxpt->Fill(jet_pt, photonMax/jet_pt, weight);
          jetptneuMaxr->Fill(jet_pt, neutralMax/TMath::Max(chargedSum,neutralSum) ,weight);
          jetptchSum->Fill(jet_pt, chargedSum, weight);
          jetptneuSum->Fill(jet_pt, neutralSum, weight);
          jetptphoSum->Fill(jet_pt, photonSum, weight);
          jetptchSumpt->Fill(jet_pt, chargedSum/jet_pt, weight);
          jetptneuSumpt->Fill(jet_pt, neutralSum/jet_pt, weight);
          jetptphoSumpt->Fill(jet_pt, photonSum/jet_pt, weight);

          jetptchN->Fill(jet_pt, chargedN, weight);
          jetptneuN->Fill(jet_pt, neutralN, weight);
          jetptphoN->Fill(jet_pt, photonN, weight);

          jetptSumSum->Fill(jet_pt, chargedSum+photonSum+neutralSum+muSum+eSum,weight);
          jetptSumSumpt->Fill(jet_pt, (chargedSum+photonSum+neutralSum+muSum+eSum)/jet_pt,weight);
          jetptSumSumrawpt->Fill(jet_pt,(chargedSum+photonSum+neutralSum+muSum+eSum)/raw_pt,weight);
	
	if(ref_pt<0){	//Added
	  jetpt_fake->Fill(jet_pt,weight);
	  jetptchMax_fake->Fill(jet_pt, chargedMax, weight);  //Added
          jetptneuMax_fake->Fill(jet_pt, neutralMax, weight);
          jetptphoMax_fake->Fill(jet_pt, photonMax, weight);
          jetptchMaxpt_fake->Fill(jet_pt, chargedMax/jet_pt, weight);
          jetptneuMaxpt_fake->Fill(jet_pt, neutralMax/jet_pt, weight);
          jetptphoMaxpt_fake->Fill(jet_pt, photonMax/jet_pt, weight);
          jetptneuMaxr_fake->Fill(jet_pt, neutralMax/TMath::Max(chargedSum,neutralSum) ,weight);
          jetptchSum_fake->Fill(jet_pt, chargedSum, weight);
          jetptneuSum_fake->Fill(jet_pt, neutralSum, weight);
          jetptphoSum_fake->Fill(jet_pt, photonSum, weight);
          jetptchSumpt_fake->Fill(jet_pt, chargedSum/jet_pt, weight);
          jetptneuSumpt_fake->Fill(jet_pt, neutralSum/jet_pt, weight);
          jetptphoSumpt_fake->Fill(jet_pt, photonSum/jet_pt, weight);

          jetptchN_fake->Fill(jet_pt, chargedN, weight);
          jetptneuN_fake->Fill(jet_pt, neutralN, weight);
          jetptphoN_fake->Fill(jet_pt, photonN, weight);

          jetptSumSum_fake->Fill(jet_pt, chargedSum+photonSum+neutralSum+muSum+eSum,weight);
          jetptSumSumpt_fake->Fill(jet_pt, (chargedSum+photonSum+neutralSum+muSum+eSum)/jet_pt,weight);
          jetptSumSumrawpt_fake->Fill(jet_pt,(chargedSum+photonSum+neutralSum+muSum+eSum)/raw_pt,weight);
	}
	else{
	  jetpt_real->Fill(jet_pt,weight);
          jetptchMax_real->Fill(jet_pt, chargedMax, weight);  //Added
          jetptneuMax_real->Fill(jet_pt, neutralMax, weight);
          jetptphoMax_real->Fill(jet_pt, photonMax, weight);
          jetptchMaxpt_real->Fill(jet_pt, chargedMax/jet_pt, weight);
          jetptneuMaxpt_real->Fill(jet_pt, neutralMax/jet_pt, weight);
          jetptphoMaxpt_real->Fill(jet_pt, photonMax/jet_pt, weight);
          jetptneuMaxr_real->Fill(jet_pt, neutralMax/TMath::Max(chargedSum,neutralSum) ,weight);
          jetptchSum_real->Fill(jet_pt, chargedSum, weight);
          jetptneuSum_real->Fill(jet_pt, neutralSum, weight);
          jetptphoSum_real->Fill(jet_pt, photonSum, weight);
          jetptchSumpt_real->Fill(jet_pt, chargedSum/jet_pt, weight);
          jetptneuSumpt_real->Fill(jet_pt, neutralSum/jet_pt, weight);
          jetptphoSumpt_real->Fill(jet_pt, photonSum/jet_pt, weight);
        
          jetptchN_real->Fill(jet_pt, chargedN, weight);
          jetptneuN_real->Fill(jet_pt, neutralN, weight);
          jetptphoN_real->Fill(jet_pt, photonN, weight);
      
          jetptSumSum_real->Fill(jet_pt, chargedSum+photonSum+neutralSum+muSum+eSum,weight);
          jetptSumSumpt_real->Fill(jet_pt, (chargedSum+photonSum+neutralSum+muSum+eSum)/jet_pt,weight);
          jetptSumSumrawpt_real->Fill(jet_pt,(chargedSum+photonSum+neutralSum+muSum+eSum)/raw_pt,weight);	
	}	
	}
	
      for(int ieta =0; ieta<netabin;ieta++){
          if(jet_eta>deta[ieta]&&jet_eta<=deta[ieta+1]) dEtaBin=ieta;
      }//assign the eta bin for jets
      if(dEtaBin!=-1){
//	 jetptEtaBin[dEtaBin]->Fill(jet_pt,weight);
	if(ref_pt<0){
//	 jetptEtaBin_fake[dEtaBin]->Fill(jet_pt,weight);
	 jetptSumSumptEtaBin_fake[dEtaBin]->Fill(jet_pt,(chargedSum+photonSum+neutralSum+muSum+eSum)/jet_pt,weight);
	 jetptchMaxptEtaBin_fake[dEtaBin]->Fill(jet_pt,chargedMax/jet_pt,weight);     //Added
	 jetptchMaxEtaBin_fake[dEtaBin]->Fill(jet_pt,chargedMax,weight);     //Added
	 jetptneuMaxrEtaBin_fake[dEtaBin]->Fill(jet_pt,neutralMax/TMath::Max(chargedSum,neutralSum),weight);
	}
	else{
//	 jetptEtaBin_real[dEtaBin]->Fill(jet_pt,weight);
	 jetptSumSumptEtaBin_real[dEtaBin]->Fill(jet_pt,(chargedSum+photonSum+neutralSum+muSum+eSum)/jet_pt,weight);
	 jetptchMaxptEtaBin_real[dEtaBin]->Fill(jet_pt,chargedMax/jet_pt,weight);     //Added
	 jetptchMaxEtaBin_real[dEtaBin]->Fill(jet_pt,chargedMax,weight);     //Added
	 jetptneuMaxrEtaBin_real[dEtaBin]->Fill(jet_pt,neutralMax/TMath::Max(chargedSum,neutralSum),weight);
	}
	 jetptchMaxEtaBin[dEtaBin]->Fill(jet_pt,chargedMax,weight);     //Added
	 jetptchMaxptEtaBin[dEtaBin]->Fill(jet_pt,chargedMax/jet_pt,weight);     //Added
//	 jetptneuMaxptEtaBin[dEtaBin]->Fill(jet_pt,neutralMax/jet_pt,weight);     //Added
//	 jetptphoMaxptEtaBin[dEtaBin]->Fill(jet_pt,photonMax/jet_pt,weight);     //Added
//	 jetptchSumptEtaBin[dEtaBin]->Fill(jet_pt,chargedSum/jet_pt,weight);     //Added
//	 jetptneuSumptEtaBin[dEtaBin]->Fill(jet_pt,neutralSum/jet_pt,weight);     //Added
//	 jetptphoSumptEtaBin[dEtaBin]->Fill(jet_pt,photonSum/jet_pt,weight);     //Added
//	 jetptSumSumrawptEtaBin[dEtaBin]->Fill(jet_pt,(chargedSum+photonSum+neutralSum+muSum+eSum)/raw_pt,weight);
	 jetptSumSumptEtaBin[dEtaBin]->Fill(jet_pt,(chargedSum+photonSum+neutralSum+muSum+eSum)/jet_pt,weight);
	 jetptneuMaxrEtaBin[dEtaBin]->Fill(jet_pt,neutralMax/TMath::Max(chargedSum,neutralSum),weight);
	}
      } //loop over jet
	
}	//loop over tree

  TString dataType;
  TString out_name;
  dataType = "MC";
  out_name=Form("%s%s%s%sskimJetID.root",dataType.Data(),coll.Data(),algo.Data(),wtype.Data());

  TFile *out_file = new TFile(Form("/home/xuq/Documents/HI/RpA/output/TreeAna/%s",out_name.Data()),"RECREATE");  

jetpt->Write();       //Added
jetptchMax->Write();       //Added
jetptchMaxpt->Write();       //Added
jetptneuMaxpt->Write(); //Added
jetptneuMaxr->Write();   //Added
jetptneuMax->Write();   //Added
jetptphoMaxpt->Write(); //Added 
jetptphoMax->Write();   //Added
jetptchSum->Write();
jetptneuSum->Write();
jetptphoSum->Write();
jetptchSumpt->Write();
jetptneuSumpt->Write();
jetptphoSumpt->Write();
jetptchN->Write();
jetptneuN->Write();
jetptphoN->Write();
jetptSumSum->Write();   //Added
jetptSumSumrawpt->Write();   //Added
jetptSumSumpt->Write();   //Added

jetpt_fake->Write();       //Added
jetpt_real->Write();       //Added
 jetptchMax_fake->Write();	//Added
 jetptchMax_real->Write();	//Added
  jetptchMaxpt_fake->Write();       //Added
  jetptchMaxpt_real->Write();       //Added
  jetptneuMaxpt_fake->Write();    //Added
  jetptneuMaxpt_real->Write();    //Added
    jetptneuMaxr_fake->Write();      //Added
    jetptneuMaxr_real->Write();      //Added
    jetptneuMax_fake->Write();      //Added
    jetptneuMax_real->Write();      //Added
    jetptphoMaxpt_fake->Write();    //Added
    jetptphoMaxpt_real->Write();    //Added
    jetptphoMax_fake->Write();      //Added
    jetptphoMax_real->Write();      //Added
 	  jetptchSum_fake->Write();
 	  jetptchSum_real->Write();
 	  jetptneuSum_fake->Write();
 	  jetptneuSum_real->Write();
 	  jetptphoSum_fake->Write();
 	  jetptphoSum_real->Write();
 	  jetptchSumpt_fake->Write();
 	  jetptchSumpt_real->Write();
 	  jetptneuSumpt_fake->Write();
 	  jetptneuSumpt_real->Write();
 	  jetptphoSumpt_fake->Write();
 	  jetptphoSumpt_real->Write();
 	  jetptchN_fake->Write();
 	  jetptchN_real->Write();
    jetptneuN_fake->Write();
    jetptneuN_real->Write();
    jetptphoN_fake->Write();
    jetptphoN_real->Write();
    jetptSumSum_fake->Write();      //Added
    jetptSumSum_real->Write();      //Added
    jetptSumSumrawpt_fake->Write();      //Added
    jetptSumSumrawpt_real->Write();      //Added
    jetptSumSumpt_fake->Write();      //Added
    jetptSumSumpt_real->Write();      //Added
    for(int ieta=0; ieta<netabin; ieta++){
	 jetptEtaBin[ieta]->Write();     //Added
	 jetptEtaBin_real[ieta]->Write();     //Added
	 jetptEtaBin_fake[ieta]->Write();     //Added
	 jetptchMaxEtaBin[ieta]->Write();     //Added
	 jetptchMaxEtaBin_fake[ieta]->Write();     //Added
	 jetptchMaxEtaBin_real[ieta]->Write();     //Added
	 jetptchMaxptEtaBin[ieta]->Write();     //Added
	 jetptchMaxptEtaBin_fake[ieta]->Write();     //Added
	 jetptchMaxptEtaBin_real[ieta]->Write();     //Added
	 jetptneuMaxptEtaBin[ieta]->Write();    //Added
	 jetptneuMaxrEtaBin[ieta]->Write();     //Added
	 jetptneuMaxrEtaBin_fake[ieta]->Write();     //Added
	 jetptneuMaxrEtaBin_real[ieta]->Write();     //Added
	 jetptphoMaxptEtaBin[ieta]->Write();    //Added
	 jetptchSumptEtaBin[ieta]->Write();     //Added
  	 jetptneuSumptEtaBin[ieta]->Write();    //Added
	 jetptphoSumptEtaBin[ieta]->Write();    //Added
	 jetptSumSumptEtaBin[ieta]->Write();    //Added
	 jetptSumSumptEtaBin_fake[ieta]->Write();    //Added
	 jetptSumSumptEtaBin_real[ieta]->Write();    //Added
	 jetptSumSumrawptEtaBin[ieta]->Write();         //Added
 	 }
  out_file->Close();
  cout<<"Output file: "<<Form("%s",out_name.Data())<<endl;

  cout<<"working done\n";

}
示例#29
0
void unfold(TString RR){

        bool CLOSURE_TEST = false;

        TString POSTFIX_corr = "";
        if (FEWZ_CORRECTED) POSTFIX_corr = "_corr";

        //SET UP ROO
        gSystem->Load("RooUnfold-1.1.1/libRooUnfold.so");

	TString _trig = "HLT_Double";
        TString resRR = "_"+RR;
        if (RR == "POWHEG") {
          CLOSURE_TEST = true;
        }
        _inFile = new TFile("../Inputs/unfold/resMatrixProd"+resRR+"_tmp.root");

        //
        //STEP0: GET HISTOGRAMS FROM THE PREVIOUS FILE
        //
	_inTrue = (TH1F*)_inFile->Get("htrue"+POSTFIX_corr);
        cout << "htrue"+POSTFIX_corr << endl;
	_inMeasMC= (TH1F*)_inFile->Get("hmeas"+POSTFIX_corr);
        _inEvMat = (TH2F*)_inFile->Get("hden"+POSTFIX_corr);

        TString yRR = RR;
        if (RR == "POWHEG") yRR = "_";

        TFile* _inData = new TFile("../Inputs/rawYield/DYspectrum_uncorr_2013"+yRR+"tmp.root");
        _inData->cd();
        TH1F* sigNorm = (TH1F*)hsig_fewz->Clone();
        //FIXME rescale to get Lumi independent normalization
        _inTrue->Scale(sigNorm->Integral()/_inTrue->Integral()); //10,22));
        _inMeasMC->Scale(sigNorm->Integral()/_inMeasMC->Integral());
        _inEvMat->Scale(sigNorm->Integral()/_inEvMat->Integral());
        normalizeToPeak(_inTrue,sigNorm);
        normalizeToPeak(_inMeasMC,sigNorm);
        normalizeToPeak2D(_inEvMat,sigNorm);
        cout << "Cross check " << double(_inMeasMC->Integral(10,22))/sigNorm->Integral(10,22)<< endl;
        _inData->Close();

        _inMigMat = getMigMatrix(_inTrue,_inEvMat); //(TH2F*)_inFile->Get("migMatrix");

        if (USE_OVERFLOWS && !DO_ROO) _inTrue = rebinWithOU1(_inTrue);
        if (USE_OVERFLOWS && !DO_ROO) _inMeasMC = rebinWithOU1(_inMeasMC);
        if (USE_OVERFLOWS && !DO_ROO) _inMigMat =  rebinWithOU2(_inMigMat);

        _inMeas = (TH1F*)_inMeasMC->Clone("inMeas");
        _inMeasData = (TH1F*)_inMeasMC->Clone("inMeas");

	_inResMat = (TH2F*)_inMigMat->Clone("resMatrix");
	_inMeas->Reset();
      
        //STEP1: subtract the bacgrkounds
        if (!CLOSURE_TEST) { 

          TFile* _inData = new TFile("../Inputs/rawYield/DYspectrum_uncorr_2013"+yRR+"tmp.root");
          _inData->cd();
          //TH1F* hdata = (TH1F*)hdata->Clone();

          for( int i=0; i < hdata->GetXaxis()->GetNbins()+1; i++ ) { //FIXME should be up to +2? The last one takes the overflow into account
             //FIXME no underflow for QCD in the current result, extrapolate with constant 
             if (i==0) hqcd->SetBinContent(0,hqcd->GetBinContent(1)); 
             _inMeasData->SetBinContent(i, hdata->GetBinContent(i) - (hqcd->GetBinContent(i) + httbar->GetBinContent(i) + hDYtautau->GetBinContent(i) + hWlepton->GetBinContent(i) + hdiboson->GetBinContent(i)));
             _inMeasData->SetBinError(i, sqrt(pow(hdata->GetBinError(i),2) + pow(hqcd->GetBinError(i),2) + pow(httbar->GetBinError(i),2) + pow(hDYtautau->GetBinError(i),2) + pow(hWlepton->GetBinError(i),2) + pow(hdiboson->GetBinError(i),2)));
           }
           if (USE_OVERFLOWS && !DO_ROO) { 
             _inMeasData = rebinWithOU1(_inMeasData);
           }
        }

        //
        //SET UP CANVAS TO DRAW
        //
        can = new TCanvas("can","can",800,600);
        gStyle->SetPalette(1);
        //can->SetLogy();
        can->SetLogx();

        //
        //STEP2: SET UP THE UNFOLDER CLASS
        //   
	_unfolder = new Unfolder("badger");
	_unfolder->setTrue(_inTrue);
        if (!CLOSURE_TEST) {  
          _inMeas->Add(_inMeasData);
	  _unfolder->setMeas(_inMeas);
        } else {
          _unfolder->setMeas(_inMeasMC);
        } 
	_unfolder->setMigrationMatrix(_inResMat);
	_unfolder->unfold();
	_unfolder->getUnfolded()->SetLineColor(kRed);//Draw();	
        _unfolder->getTrue()->GetXaxis()->SetTitle("M_{#mu#mu} [GeV]");
        _unfolder->getTrue()->GetYaxis()->SetTitle("Events");
        _unfolder->getTrue()->GetXaxis()->SetMoreLogLabels();
        _unfolder->getTrue()->GetXaxis()->SetRangeUser(15,1499);
	_unfolder->getTrue()->Draw("hist");	

        //
        //STEP3: DO UNFOLDING
        //
        TH1F* crap;
        if (!DO_ROO) {        
	  crap = (TH1F*)_unfolder->getUnfolded();//->Clone("hunfolded");//Draw();	
	  _htrue = (TH1F*)_unfolder->getTrue();
         
	  //crap->Print("all");	
        } else { 
          if (!DO_BAYES) {
             RooUnfoldResponse response(_inMeasMC,_inTrue,_inEvMat); //_h2_tmp); //_inResMat);
          } else {
             RooUnfoldResponse response(_inMeasMC,_inTrue,_inResMat);
          }
          if (USE_OVERFLOWS) response.UseOverflow();
          if (CLOSURE_TEST) {
             if (DO_BAYES) { 
                RooUnfoldBayes unfoldBayes(&response, _inMeasMC, 1);
             } else {
                RooUnfoldSvd unfoldSVD(&response, _inMeasMC, 2);
             }
          } else  { 
             if (DO_BAYES) { 
		RooUnfoldBayes unfoldBayes(&response, _inMeasData, 1);
             } else {
                RooUnfoldSvd unfoldSVD(&response, _inMeasData, 2);
             }
          }
          if (DO_BAYES) { 
              crap = (TH1F*) unfoldBayes.Hreco();
          } else { 
              crap = (TH1F*) unfoldSVD.Hreco(); //analog of getUnfolded() in unfolder class
          }
        }

        crap->SetMarkerStyle(20);
        crap->SetMarkerColor(kRed);
        crap->Draw("same"); 

        TLegend* leg = MakeLegend();
        leg->AddEntry(_unfolder->getTrue(),"True","l");
        if (CLOSURE_TEST) {
          leg->AddEntry(crap,"Unfolded MC","lp");
        } else {
          leg->AddEntry(crap,"Unfolded","lp");
        }
        leg->Draw("same");
        can->SaveAs("plot"+resRR+".png");

        //
        //STEP4: ALL DONE SAVING OUTPUT
        //
        TH2F* invrseResMat = (TH2F*)_unfolder->matrixToHist(_unfolder->getMigMatInverse(),_inResMat);
        if (USE_OVERFLOWS && !DO_ROO) {
          _inMeas = rebinWithNoOU1(_inMeas);
          _inTrue = rebinWithNoOU1(_inTrue);
        }
        if (USE_OVERFLOWS && !DO_ROO) {
          crap = rebinWithNoOU1(crap);
        } 

        _outFile = new TFile("rootfiles/unfoldData_"+_trig+"_"+RR+".root","recreate");
        _outFile->cd();
        invrseResMat->Write("inverse_Response");
        _inMeas->Write("hmeas");
	crap->Write("hunfolded");
	_inTrue->Write("htrue");
	_outFile->Write();

        //check dims before and after
        //_unfolder->getMigMatInverse()->Print();


	return;		
	//_unfolder->getMigMat()->Print();
	//_unfolder->getMigMatInverse()->Print();

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

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

c2->cd(2);
h->SetMinimum(0.);
h->SetMaximum(2);
SetTitle(h,"","p_{T}","v_{2} ratio BBCs/FVTXs");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[4][idire][iCNTEP],gr[5][idire][iCNTEP]);
SetStyle(*grr,1.2,color[idire+3*iCNTEP],style[2]);
grr->Draw("Psame");
c2->Print(Form("FVTXvsBBCv%d.png",n));
/*
TCanvas *c3 = new TCanvas("c3","c3",800,450);
idire = 0;
isub=5;
c3->Divide(2);
c3->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(h,"","p_{T}","v_{2}^{raw}");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
gr[isub][idire][1]->Draw("Psame");
gr[isub][idire][0]->Draw("Psame");
leg->AddEntry(gr[isub][idire][1],Form("FVTXs -3.0<#eta<-1.0"));
leg->AddEntry(gr[isub][idire][1],Form("Using Psi EP"),"P");
leg->AddEntry(gr[isub][idire][0],Form("Using phi EP"),"P");
leg->Draw("Psame");

c3->cd(2);
h->SetMinimum(0.8);
h->SetMaximum(1.2);
SetTitle(h,"","p_{T}","v_{2} ratio FVTXs using phi EP/using Psi EP");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][idire][0],gr[isub][idire][1]);
SetStyle(*grr,1.2,color[idire+3*0],style[isub]);
grr->Draw("Psame");
*/
TCanvas *c4 = new TCanvas("c4","c4",800,450);
isub=3;
iCNTEP = 0;
c4->Divide(2);
c4->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(*h,"p_{T} (GeV/c)","v_{2}","");
h->DrawCopy();
TLegend *leg = new TLegend(0.2,0.7,0.5,0.9);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
gr[isub][0][iCNTEP]->Draw("Psame");
gr[isub][1][iCNTEP]->Draw("Psame");
gr[isub][2][iCNTEP]->Draw("Psame");
if(isub==5)
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs -3.0<#eta<-1.0"));
else if(isub<4)
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer %d -3.0<#eta<-1.0", isub+1));
else if(isub==6)
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer 2+4"));
else if(isub==7)
leg->AddEntry(gr[isub][0][iCNTEP],Form("FVTXs Layer 1+2+4"));
leg->AddEntry(gr[isub][0][iCNTEP],Form("inclusive"),"P");
leg->AddEntry(gr[isub][1][iCNTEP],Form("East"),"P");
leg->AddEntry(gr[isub][2][iCNTEP],Form("West"),"P");
leg->Draw("Psame");

c4->cd(2);
h->SetMinimum(0);
h->SetMaximum(2);
SetTitle(*h,"p_{T} (GeV/c)","v_{2} ratio","");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
c4->Print(Form("v%dFVTXs%dEW.png",n,isub));

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

c5->cd(2);
h->SetMinimum(0);
h->SetMaximum(2.);
SetTitle(h,"","p_{T}","v_{2} ratio");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][1][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[1+3*iCNTEP],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors*)DivideTwoGraphs(gr[isub][2][iCNTEP],gr[isub][0][iCNTEP]);
SetStyle(*grr,1.2,color[2+3*iCNTEP],style[isub]);
grr->Draw("Psame");
c5->Print(Form("v%dBBCs%dEW.png",n,isub));

TCanvas *c6 = new TCanvas("c6","c6",800,450);
iCNTEP = 0;
c6->Divide(2);
c6->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(*h,"p_{T}","v_{2}","");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.5,0.65,0.8,0.85);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
SetStyle(*gr[0][0][iCNTEP], 1.2, color[0],style[0]);
SetStyle(*gr[1][0][iCNTEP], 1.2, color[1],style[1]);
SetStyle(*gr[2][0][iCNTEP], 1.2, color[2],style[2]);
SetStyle(*gr[3][0][iCNTEP], 1.2, color[3],style[3]);
SetStyle(*gr[5][0][iCNTEP], 1.2, color[5],style[5]);
gr[0][0][iCNTEP]->Draw("Psame");
gr[1][0][iCNTEP]->Draw("Psame");
gr[2][0][iCNTEP]->Draw("Psame");
gr[3][0][iCNTEP]->Draw("Psame");
gr[5][0][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[0][0][iCNTEP],Form("FVTX 1LS"),"P");
leg->AddEntry(gr[1][0][iCNTEP],Form("FVTX 2LS"),"P");
leg->AddEntry(gr[2][0][iCNTEP],Form("FVTX 3LS"),"P");
leg->AddEntry(gr[3][0][iCNTEP],Form("FVTX 4LS"),"P");
leg->AddEntry(gr[5][0][iCNTEP],Form("FVTX All"),"P");
leg->Draw("same");

c6->cd(2);
h->SetMinimum(0.5);
h->SetMaximum(1.5);
SetTitle(*h,"p_{T}","v_{2} ratio","");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[0][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[0],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[1][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[1],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[2][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[2],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[3][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[3],style[isub]);
grr->Draw("Psame");
c6->Print(Form("FVTXeachlayerv%d.png",n));


TCanvas *c7 = new TCanvas("c7","c7",800,450);
iCNTEP = 0;
c7->Divide(2);
c7->cd(1);
h->SetMinimum(0);
h->SetMaximum(0.3);
SetTitle(*h,"p_{T}","v_{2}","");
//SetTitle(h,"","p_{T}","v_{2}");
h->DrawCopy();
TLegend *leg = new TLegend(0.5,0.75,0.8,0.85);
leg->SetFillColor(0);
leg->SetBorderSize(0);
leg->SetTextSize(0.04);
SetStyle(*gr[5][0][iCNTEP], 1.2, color[5],style[0]);
SetStyle(*gr[6][0][iCNTEP], 1.2, color[6],style[1]);
SetStyle(*gr[7][0][iCNTEP], 1.2, color[7],style[2]);
gr[5][0][iCNTEP]->Draw("Psame");
gr[6][0][iCNTEP]->Draw("Psame");
gr[7][0][iCNTEP]->Draw("Psame");
leg->AddEntry(gr[5][0][iCNTEP],Form("FVTX All"),"P");
leg->AddEntry(gr[6][0][iCNTEP],Form("FVTX 2+4 layer"),"P");
leg->AddEntry(gr[7][0][iCNTEP],Form("FVTX 1+2+4 layer"),"P");
leg->Draw("same");

c7->cd(2);
h->SetMinimum(0.5);
h->SetMaximum(1.5);
SetTitle(*h,"p_{T}","v_{2} ratio","");
h->DrawCopy();
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[5][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[5],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[6][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[6],style[isub]);
grr->Draw("Psame");
TGraphErrors *grr = (TGraphErrors *)DivideTwoGraphs(gr[7][0][iCNTEP],gr[5][0][iCNTEP]);
SetStyle(*grr,1.2,color[7],style[isub]);
grr->Draw("Psame");
c7->Print(Form("FVTXlayerCombv%d.png",n));
}