Example #1
0
void plotweight(int isub){
    TFile *f = TFile::Open("/phenix/u/xuq/xuq/taxi/Run15pAu200FVTXClusAna503/8845/data/435527_0.root");
    int ivz = 0;
    TH1F* h = (TH1F*)f->Get(Form("phiweight_0_0_0_%d_0_%d",ivz,isub));
    TH1F* hc = (TH1F*)h->Clone("hc");
    h->Rebin(4);
    hc->Rebin(4);
    for(int ibin=0;ibin<=h->GetNbinsX();ibin++){
        if(h->GetBinContent(ibin)!=0)
        hc->SetBinContent(ibin,h->Integral()/h->GetNbinsX()/h->GetBinContent(ibin));
        else 
        hc->SetBinContent(ibin,1.);
    }
    TCanvas *c1 = new TCanvas("c1");
    hc->Draw();
    TCanvas *c2 = new TCanvas("c2");
    h->Draw();
}
Example #2
0
File: mipana.C Project: perthi/ana
mipana()
{
  ScanConfigFile();

  //  int nBins = (int)(((int)(MAX_BIN - MIN_BIN +1))/((int)BIN_SIZE));
  //  cout << "nBins = " << nBins  << endl;
  char inFileName[256];
  char outFileName[256];
  char tmpHistoName[256];

  //  TH2F *entries;


  for(int node = 0; node < nNodes; node  ++)
    {
  
      TH1F *tmpHist;
      sprintf(inFileName,"%s_ClusterEnergies.root", nodes[node]);
      sprintf(outFileName, "%s_FilteredClusterEnergies.root", nodes[node]);
      TFile *infile  = new TFile(inFileName, "read");
      TFile *outFile = new TFile(outFileName, "recreate"); 

      for(int z =Z_MIN; z < Z_MAX; z ++  )
	{
	  for(int x = X_MIN; x < X_MAX; x ++)
	    {
	      sprintf(tmpHistoName, "ClusterEnergies3x3_2_%d_%d_1", z, x);
	  
	      tmpHist = (TH1F*)infile->Get(tmpHistoName);

	      if(tmpHist != 0)
		{
		  cout << "rebinning histogram " << tmpHistoName <<endl;
 
		  outFile->cd();
		  tmpHist->Rebin(4);
		  tmpHist->Write();
		  infile->cd();
		}
	      else
		{
		  //	      cout << "ERROR: histogram " << tmpHistoName << "  doesnt exists" <<endl; 
		}

	      //do something
	    }
	}
  
      infile->Close();
      outFile->Close();
    }
}
Example #3
0
TH1* his( TH1* input, Int_t nbins, Double_t xlow, Double_t xhigh ) {
  if ( !input ) { return 0; }
  TString name( TString(input->GetName()) + "Clone" );
  TH1F* output = new TH1F( name, "", input->GetNbinsX(), xlow, xhigh );
  for ( Int_t bin = 1; bin < input->GetNbinsX()+1; ++bin ) {
    Double_t centre = input->GetBinLowEdge(bin) + input->GetBinWidth(bin)/2.;
    if ( centre > xlow && 
	 centre < xhigh && 
	 input->GetBinContent(bin) > 0. ) {
      output->Fill( centre, input->GetBinContent(bin) );
    }
  }
  output->Sumw2();
  output->Rebin(Int_t(input->GetNbinsX()/nbins));
  return output;
}
Example #4
0
void BackgroundFit() {
    TFile* inputFile = new TFile("0_MuScleFit.root", "READ");
    TH1F* histo = (TH1F*)inputFile->FindObjectAny("hRecBestRes_Mass");
    histo->Rebin(30);
    histo->Scale(1/histo->GetEntries());

    // TF1 * functionToFit = lorentzianFit();
    // TF1 * functionToFit = crystalBallFit();
    // TF1 * functionToFit = powerLawFit();
    // TF1 * functionToFit = lorentzianAndPowerLaw();
    // TF1 * functionToFit = exponentialFit();
    TF1 * functionToFit = lorenzianAndExponentialFit();

    histo->Fit(functionToFit, "M", "", 42, 160);

}
Example #5
0
TH1F* readHist(TString nameHist,TString nameFile, TString nameDir, int rebin)
{
 TFile* file = new TFile(nameFile);
 file->ls();
 TDirectory *dir=(TDirectory*)file->Get(nameDir);
 
 TH1F* hist = (TH1F*)dir->Get(nameHist);
 // if (hist==0) return;
 hist->GetSumw2();
 // hist->SetLineWidth(2);
 if(rebin>0) hist->Rebin(rebin);
 hist->GetXaxis()->SetTitleSize(.055);
 hist->GetYaxis()->SetTitleSize(.055);
 hist->GetXaxis()->SetLabelSize(.05);
 hist->GetYaxis()->SetLabelSize(.05);
 hist->SetStats(kFALSE);
 return hist;
}
Example #6
0
void rebin() {
   //create a fix bin histogram
   TH1F *h = new TH1F("h","test rebin",100,-3,3);
   Int_t nentries = 1000;
   h->FillRandom("gaus",nentries);
   Double_t xbins[1001];
   Int_t k=0;
   TAxis *axis = h->GetXaxis();
   for (Int_t i=1;i<=100;i++) {
      Int_t y = (Int_t)h->GetBinContent(i);
      if (y <=0) continue;
      Double_t dx = axis->GetBinWidth(i)/y;
      Double_t xmin = axis->GetBinLowEdge(i);
      for (Int_t j=0;j<y;j++) {
         xbins[k] = xmin +j*dx;
         k++;
      }
   }
   xbins[k] = axis->GetXmax();
   //create a variable bin-width histogram out of fix bin histogram
   //new rebinned histogram should have about 10 entries per bin
   TH1F *hnew = new TH1F("hnew","rebinned",k,xbins);
   hnew->FillRandom("gaus",10*nentries);

   //rebin hnew keeping only 50% of the bins
   Double_t xbins2[501];
   Int_t kk=0;
   for (Int_t j=0;j<k;j+=2) {
      xbins2[kk] = xbins[j];
      kk++;
   }
   xbins2[kk] = xbins[k];
   TH1F *hnew2 = (TH1F*)hnew->Rebin(kk,"hnew2",xbins2);

   //draw the 3 histograms
   TCanvas *c1 = new TCanvas("c1","c1",800,1000);
   c1->Divide(1,3);
   c1->cd(1);
   h->Draw();
   c1->cd(2);
   hnew->Draw();
   c1->cd(3);
   hnew2->Draw();
}
Example #7
0
void ProbsFitter()
{
  TFile * inputFile = new TFile("Sherpa_nocuts.root", "READ");
  TH1F * histo = (TH1F*)inputFile->FindObjectAny("HistAllZMass");
  histo->Scale(1/histo->GetEntries());
  histo->Rebin(6);
  TCanvas * canvas = new TCanvas("canvas", "canvas", 1000, 800);
  canvas->Divide(2,3);

  // gStyle->SetOptFit(1);

  TF1 * residuals1 = iterateFitter(histo, 0, 0, canvas);
//   TF1 * residuals2 = iterateFitter(histo, 1, residuals1, canvas);
//   iterateFitter(histo, 2, residuals2, canvas);

//   canvas->cd(3);
//   TH1F * hclone = (TH1F*)histo->Clone();
//   TF1 * combinedFunctionToFit = combinedFit(residualFitFunction->GetParameters());
//   hclone->Fit(combinedFunctionToFit, "MN", "", 60, 120);
//   hclone->Draw();
//   combinedFunctionToFit->Draw("same");
//   combinedFunctionToFit->SetLineColor(kRed);

}
Example #8
0
void BINcomb(){

  TFile *fqcd = new TFile("QCD.root");
  TFile *fsig = new TFile("SIG.root");
  TFile *fttb = new TFile("TTB.root");

  double xcqcd = 25.42*1000; 
  double xcttb = 831.76*1000; 
  double xcsig = 0.0624391*1000;
  
  double lumi = 5.0 ; 
  

  double nt_qcd = xcqcd*lumi; 
  double nt_sig = xcsig*lumi; 
  double nt_ttb = xcttb*lumi; 

  fqcd->cd();
  demo->cd();
  double scf_qcd = nt_qcd/(1.0*Ev0->GetEntries()); 

  TH1F *ak8ptq = ak8pt->Clone();
  TH1F *t31q = ak8t31->Clone();
  TH1F *ak8_phosubfq = ak8_phosubFrac->Clone();  
  TH1F *pm0q = ak8_prunnedM0->Clone(); 
  TH1F *pm1q = ak8_prunnedM1->Clone(); 
  TH1F *pm2q = ak8_prunnedM2->Clone(); 
  TH1F *pm3q = ak8_prunnedM3->Clone(); 
  TH1F *pm4q = ak8_prunnedM4->Clone(); 
  TH1F *pm5q = ak8_prunnedM5->Clone(); 
  TH1F *njt3q = NJT3->Clone();
  TH1F *njl3q = NJL3->Clone();
  TH1F *njt4q = NJT4->Clone();
  TH1F *njl4q = NJL4->Clone();
  TH1F *htaq = HTa->Clone();
  TH1F *ht3q = HT3->Clone();
  TH1F *ht4q = HT4->Clone();
  TH1F *ht4l1q = HT4L1->Clone();
  TH1F *ht4l2q = HT4L2->Clone();
  TH1F *ht4t1q = HT4T1->Clone();
  TH1F *ht4t2q = HT4T2->Clone();
  TH1F *ht3l1q = HT3L1->Clone();
  TH1F *ht3l2q = HT3L2->Clone();
  TH1F *ht3t1q = HT3T1->Clone();
  TH1F *ht3t2q = HT3T2->Clone();
  
  TH1F *Thotmassq = T2jet_4evmasspruned->Clone();
  TH1F *Lhotmassq = L3jet_4evmasspruned->Clone();
 

  fttb->cd();
  demo->cd();
  double scf_ttb = nt_ttb/(1.0*Ev0->GetEntries()); 



  TH1F *Thotmasst = T2jet_4evmasspruned->Clone();
  TH1F *Lhotmasst = L3jet_4evmasspruned->Clone();
 
 
  TH1F *ak8ptt = ak8pt->Clone();
  TH1F *t31t = ak8t31->Clone();
  TH1F *ak8_phosubft = ak8_phosubFrac->Clone();  
  TH1F *pm0t = ak8_prunnedM0->Clone(); 
  TH1F *pm1t = ak8_prunnedM1->Clone(); 
  TH1F *pm2t = ak8_prunnedM2->Clone(); 
  TH1F *pm3t = ak8_prunnedM3->Clone(); 
  TH1F *pm4t = ak8_prunnedM4->Clone(); 
  TH1F *pm5t = ak8_prunnedM5->Clone(); 
  TH1F *njt3t = NJT3->Clone();
  TH1F *njl3t = NJL3->Clone();
  TH1F *njt4t = NJT4->Clone();
  TH1F *njl4t = NJL4->Clone();
  TH1F *htat = HTa->Clone();
  TH1F *ht3t = HT3->Clone();
  TH1F *ht4t = HT4->Clone();
  TH1F *ht4l1t = HT4L1->Clone();
  TH1F *ht4l2t = HT4L2->Clone();
  TH1F *ht4t1t = HT4T1->Clone();
  TH1F *ht4t2t = HT4T2->Clone();
  TH1F *ht3l1t = HT3L1->Clone();
  TH1F *ht3l2t = HT3L2->Clone();
  TH1F *ht3t1t = HT3T1->Clone();
  TH1F *ht3t2t = HT3T2->Clone();


  fsig->cd();
  demo->cd();
  double scf_sig = nt_sig/(1.0*Ev0->GetEntries()); 

  TH1F *Thotmasss = T2jet_4evmasspruned->Clone();
  TH1F *Lhotmasss = L3jet_4evmasspruned->Clone();
 

  TH1F *ak8pts = ak8pt->Clone();
  TH1F *t31s = ak8t31->Clone();
  TH1F *ak8_phosubfs = ak8_phosubFrac->Clone();  
  TH1F *pm0s = ak8_prunnedM0->Clone(); 
  TH1F *pm1s = ak8_prunnedM1->Clone(); 
  TH1F *pm2s = ak8_prunnedM2->Clone(); 
  TH1F *pm3s = ak8_prunnedM3->Clone(); 
  TH1F *pm4s = ak8_prunnedM4->Clone(); 
  TH1F *pm5s = ak8_prunnedM5->Clone(); 
  TH1F *njt3s = NJT3->Clone();
  TH1F *njl3s = NJL3->Clone();
  TH1F *njt4s = NJT4->Clone();
  TH1F *njl4s = NJL4->Clone();
  TH1F *htas = HTa->Clone();
  TH1F *ht3s = HT3->Clone();
  TH1F *ht4s = HT4->Clone();
  TH1F *ht4l1s = HT4L1->Clone();
  TH1F *ht4l2s = HT4L2->Clone();
  TH1F *ht4t1s = HT4T1->Clone();
  TH1F *ht4t2s = HT4T2->Clone();
  TH1F *ht3l1s = HT3L1->Clone();
  TH1F *ht3l2s = HT3L2->Clone();
  TH1F *ht3t1s = HT3T1->Clone();
  TH1F *ht3t2s = HT3T2->Clone();


  //Scaling all the historgrams: 
  ak8pts->Scale(scf_sig);
  t31s->Scale(scf_sig);
  ak8_phosubfs->Scale(scf_sig);
  pm0s->Scale(scf_sig);
  pm1s->Scale(scf_sig);
  pm2s->Scale(scf_sig);
  pm3s->Scale(scf_sig);
  pm4s->Scale(scf_sig);
  pm5s->Scale(scf_sig);
  njt3s->Scale(scf_sig);
  njl3s->Scale(scf_sig);
  njt4s->Scale(scf_sig);
  njl4s->Scale(scf_sig);
  htas->Scale(scf_sig);
  ht3s->Scale(scf_sig);
  ht4s->Scale(scf_sig);
  ht4l1s->Scale(scf_sig);
  ht4l2s->Scale(scf_sig);
  ht4t1s->Scale(scf_sig);
  ht4t2s->Scale(scf_sig);
  ht3l1s->Scale(scf_sig);
  ht3l2s->Scale(scf_sig);
  ht3t1s->Scale(scf_sig);
  ht3t2s->Scale(scf_sig);
  Thotmasss->Scale(scf_sig);
  Lhotmasss->Scale(scf_sig);




 Thotmasss->SetFillColor(kRed);
 Lhotmasss->SetFillColor(kRed);
  ak8pts->SetFillColor(kRed);
  t31s->SetFillColor(kRed);

  
  ak8_phosubfs->SetFillColor(kRed);
  pm0s->SetFillColor(kRed);
  pm1s->SetFillColor(kRed);
  pm2s->SetFillColor(kRed);
  pm3s->SetFillColor(kRed);
  pm4s->SetFillColor(kRed);
  pm5s->SetFillColor(kRed);
  njt3s->SetFillColor(kRed);
  njl3s->SetFillColor(kRed);
  njt4s->SetFillColor(kRed);
  njl4s->SetFillColor(kRed);
  htas->SetFillColor(kRed);
  ht3s->SetFillColor(kRed);
  ht4s->SetFillColor(kRed);
  ht4l1s->SetFillColor(kRed);
  ht4l2s->SetFillColor(kRed);
  ht4t1s->SetFillColor(kRed);
  ht4t2s->SetFillColor(kRed);
  ht3l1s->SetFillColor(kRed);
  ht3l2s->SetFillColor(kRed);
  ht3t1s->SetFillColor(kRed);
  ht3t2s->SetFillColor(kRed);


  Thotmasss->SetLineColor(kRed);
  Lhotmasss->SetLineColor(kRed);
  
  ak8pts->SetLineColor(kRed);
  t31s->SetLineColor(kRed);
  ak8_phosubfs->SetLineColor(kRed);
  pm0s->SetLineColor(kRed);
  pm1s->SetLineColor(kRed);
  pm2s->SetLineColor(kRed);
  pm3s->SetLineColor(kRed);
  pm4s->SetLineColor(kRed);
  pm5s->SetLineColor(kRed);
  njt3s->SetLineColor(kRed);
  njl3s->SetLineColor(kRed);
  njt4s->SetLineColor(kRed);
  njl4s->SetLineColor(kRed);
  htas->SetLineColor(kRed);
  ht3s->SetLineColor(kRed);
  ht4s->SetLineColor(kRed);
  ht4l1s->SetLineColor(kRed);
  ht4l2s->SetLineColor(kRed);
  ht4t1s->SetLineColor(kRed);
  ht4t2s->SetLineColor(kRed);
  ht3l1s->SetLineColor(kRed);
  ht3l2s->SetLineColor(kRed);
  ht3t1s->SetLineColor(kRed);
  ht3t2s->SetLineColor(kRed);




  ak8ptq->Scale(scf_qcd);
  t31q->Scale(scf_qcd);
  ak8_phosubfq->Scale(scf_qcd);
  pm0q->Scale(scf_qcd);
  pm1q->Scale(scf_qcd);
  pm2q->Scale(scf_qcd);
  pm3q->Scale(scf_qcd);
  pm4q->Scale(scf_qcd);
  pm5q->Scale(scf_qcd);
  njt3q->Scale(scf_qcd);
  njl3q->Scale(scf_qcd);
  njt4q->Scale(scf_qcd);
  njl4q->Scale(scf_qcd);
  htaq->Scale(scf_qcd);
  ht3q->Scale(scf_qcd);
  ht4q->Scale(scf_qcd);
  ht4l1q->Scale(scf_qcd);
  ht4l2q->Scale(scf_qcd);
  ht4t1q->Scale(scf_qcd);
  ht4t2q->Scale(scf_qcd);
  ht3l1q->Scale(scf_qcd);
  ht3l2q->Scale(scf_qcd);
  ht3t1q->Scale(scf_qcd);
  ht3t2q->Scale(scf_qcd);

  Thotmassq->Scale(scf_qcd);
  Lhotmassq->Scale(scf_qcd);

  
  
  Thotmassq->SetFillColor(kGray+3);
  Lhotmassq->SetFillColor(kGray+3);

  ak8ptq->SetFillColor(kGray+3);
  t31q->SetFillColor(kGray+3);
  ak8_phosubfq->SetFillColor(kGray+3);
  pm0q->SetFillColor(kGray+3);
  pm1q->SetFillColor(kGray+3);
  pm2q->SetFillColor(kGray+3);
  pm3q->SetFillColor(kGray+3);
  pm4q->SetFillColor(kGray+3);
  pm5q->SetFillColor(kGray+3);
  njt3q->SetFillColor(kGray+3);
  njl3q->SetFillColor(kGray+3);
  njt4q->SetFillColor(kGray+3);
  njl4q->SetFillColor(kGray+3);
  htaq->SetFillColor(kGray+3);
  ht3q->SetFillColor(kGray+3);
  ht4q->SetFillColor(kGray+3);
  ht4l1q->SetFillColor(kGray+3);
  ht4l2q->SetFillColor(kGray+3);
  ht4t1q->SetFillColor(kGray+3);
  ht4t2q->SetFillColor(kGray+3);
  ht3l1q->SetFillColor(kGray+3);
  ht3l2q->SetFillColor(kGray+3);
  ht3t1q->SetFillColor(kGray+3);
  ht3t2q->SetFillColor(kGray+3);

  
  Thotmassq->SetLineColor(kGray+3);
  Lhotmassq->SetLineColor(kGray+3);

  ak8ptq->SetLineColor(kGray+3);
  t31q->SetLineColor(kGray+3);
  ak8_phosubfq->SetLineColor(kGray+3);
  pm0q->SetLineColor(kGray+3);
  pm1q->SetLineColor(kGray+3);
  pm2q->SetLineColor(kGray+3);
  pm3q->SetLineColor(kGray+3);
  pm4q->SetLineColor(kGray+3);
  pm5q->SetLineColor(kGray+3);
  njt3q->SetLineColor(kGray+3);
  njl3q->SetLineColor(kGray+3);
  njt4q->SetLineColor(kGray+3);
  njl4q->SetLineColor(kGray+3);
  htaq->SetLineColor(kGray+3);
  ht3q->SetLineColor(kGray+3);
  ht4q->SetLineColor(kGray+3);
  ht4l1q->SetLineColor(kGray+3);
  ht4l2q->SetLineColor(kGray+3);
  ht4t1q->SetLineColor(kGray+3);
  ht4t2q->SetLineColor(kGray+3);
  ht3l1q->SetLineColor(kGray+3);
  ht3l2q->SetLineColor(kGray+3);
  ht3t1q->SetLineColor(kGray+3);
  ht3t2q->SetLineColor(kGray+3);



 
  ak8ptt->Scale(scf_ttb);
  t31t->Scale(scf_ttb);
  ak8_phosubft->Scale(scf_ttb);
  pm0t->Scale(scf_ttb);
  pm1t->Scale(scf_ttb);
  pm2t->Scale(scf_ttb);
  pm3t->Scale(scf_ttb);
  pm4t->Scale(scf_ttb);
  pm5t->Scale(scf_ttb);
  njt3t->Scale(scf_ttb);
  njl3t->Scale(scf_ttb);
  njt4t->Scale(scf_ttb);
  njl4t->Scale(scf_ttb);
  htat->Scale(scf_ttb);
  ht3t->Scale(scf_ttb);
  ht4t->Scale(scf_ttb);
  ht4l1t->Scale(scf_ttb);
  ht4l2t->Scale(scf_ttb);
  ht4t1t->Scale(scf_ttb);
  ht4t2t->Scale(scf_ttb);
  ht3l1t->Scale(scf_ttb);
  ht3l2t->Scale(scf_ttb);
  ht3t1t->Scale(scf_ttb);
  ht3t2t->Scale(scf_ttb);


  Thotmasst->Scale(scf_ttb);
  Lhotmasst->Scale(scf_ttb);

  
  Thotmasst->SetFillColor(kMagenta);
  Lhotmasst->SetFillColor(kMagenta);
  
  ak8ptt->SetFillColor(kMagenta);
  t31t->SetFillColor(kMagenta);
  ak8_phosubft->SetFillColor(kMagenta);
  pm0t->SetFillColor(kMagenta);
  pm1t->SetFillColor(kMagenta);
  pm2t->SetFillColor(kMagenta);
  pm3t->SetFillColor(kMagenta);
  pm4t->SetFillColor(kMagenta);
  pm5t->SetFillColor(kMagenta);
  njt3t->SetFillColor(kMagenta);
  njl3t->SetFillColor(kMagenta);
  njt4t->SetFillColor(kMagenta);
  njl4t->SetFillColor(kMagenta);
  htat->SetFillColor(kMagenta);
  ht3t->SetFillColor(kMagenta);
  ht4t->SetFillColor(kMagenta);
  ht4l1t->SetFillColor(kMagenta);
  ht4l2t->SetFillColor(kMagenta);
  ht4t1t->SetFillColor(kMagenta);
  ht4t2t->SetFillColor(kMagenta);
  ht3l1t->SetFillColor(kMagenta);
  ht3l2t->SetFillColor(kMagenta);
  ht3t1t->SetFillColor(kMagenta);
  ht3t2t->SetFillColor(kMagenta);


  Thotmasst->SetLineColor(kMagenta);
  Lhotmasst->SetLineColor(kMagenta);
  
  ak8ptt->SetLineColor(kMagenta);
  t31t->SetLineColor(kMagenta);
  ak8_phosubft->SetLineColor(kMagenta);
  pm0t->SetLineColor(kMagenta);
  pm1t->SetLineColor(kMagenta);
  pm2t->SetLineColor(kMagenta);
  pm3t->SetLineColor(kMagenta);
  pm4t->SetLineColor(kMagenta);
  pm5t->SetLineColor(kMagenta);
  njt3t->SetLineColor(kMagenta);
  njl3t->SetLineColor(kMagenta);
  njt4t->SetLineColor(kMagenta);
  njl4t->SetLineColor(kMagenta);
  htat->SetLineColor(kMagenta);
  ht3t->SetLineColor(kMagenta);
  ht4t->SetLineColor(kMagenta);
  ht4l1t->SetLineColor(kMagenta);
  ht4l2t->SetLineColor(kMagenta);
  ht4t1t->SetLineColor(kMagenta);
  ht4t2t->SetLineColor(kMagenta);
  ht3l1t->SetLineColor(kMagenta);
  ht3l2t->SetLineColor(kMagenta);
  ht3t1t->SetLineColor(kMagenta);
  ht3t2t->SetLineColor(kMagenta);





  
  THStack *hpt     = new THStack("hpt","JetsPt");
  hpt->Add(ak8ptq);
  hpt->Add(ak8ptt);
  hpt->Add(ak8pts);


  THStack *ht31    = new THStack("ht31","JetsPt");
  ht31->Add(t31q);
  ht31->Add(t31t);
  ht31->Add(t31s);

  THStack *hphos   = new THStack("hphos","JetsPt");
  hphos->Add(ak8_phosubfq);
  hphos->Add(ak8_phosubft);
  hphos->Add(ak8_phosubfs);
  
  THStack *hhaspho = new THStack("hhaspho","JetsPt");
  //hhaspho->Add



  THStack *hm0 = new THStack("hm0","JetsPt");
  hm0->Add(pm0q);
  hm0->Add(pm0t);
  hm0->Add(pm0s);
  
  THStack *hm1 = new THStack("hm1","JetsPt");
  hm1->Add(pm1q);
  hm1->Add(pm1t);
  hm1->Add(pm1s);
 
  THStack *hm2 = new THStack("hm2","JetsPt");
  hm2->Add(pm2q);
  hm2->Add(pm2t);
  hm2->Add(pm2s);

  
  THStack *hm3 = new THStack("hm3","JetsPt");
  hm3->Add(pm3q);
  hm3->Add(pm3t);
  hm3->Add(pm3s);

  THStack *hm4 = new THStack("hm4","JetsPt");
  hm4->Add(pm4q);
  hm4->Add(pm4t);
  hm4->Add(pm4s);

  THStack *hm5 = new THStack("hm5","JetsPt");
  hm5->Add(pm5q);
  hm5->Add(pm5t);
  hm5->Add(pm5s);


  //************************


  THStack *nj3t = new THStack("nj3t","3 j Evs tight Jets");
  nj3t->Add(njt3q);
  nj3t->Add(njt3t);
  nj3t->Add(njt3s);

  THStack *nj3l = new THStack("nj3l","3 j Evs loose Jets");
  nj3l->Add(njl3q);
  nj3l->Add(njl3t);
  nj3l->Add(njl3s);

  THStack *nj4t = new THStack("nj4t","4 j Evs tight Jets");
  nj4t->Add(njt4q);
  nj4t->Add(njt4t);
  nj4t->Add(njt4s);

  THStack *nj4l = new THStack("nj4l","4 j Evs loose Jets");
  nj4l->Add(njl4q);
  nj4l->Add(njl4t);
  nj4l->Add(njl4s);

  //Rebinning the mass plots
  Lhotmassq->Rebin(2);
  Lhotmasst->Rebin(2);
  Lhotmasss->Rebin(2);
  Thotmassq->Rebin(2);
  Thotmasst->Rebin(2);
  Thotmasss->Rebin(2);



  THStack *nj4l2m = new THStack("nj4l2m","4 j mass Evs loose Jets");
  nj4l2m->Add(Lhotmassq);
  nj4l2m->Add(Lhotmasst);
  nj4l2m->Add(Lhotmasss);

  THStack *nj4T2m = new THStack("nj4T2m","4 j mass Evs Tight Jets");
  nj4T2m->Add(Thotmassq);
  nj4T2m->Add(Thotmasst);
  nj4T2m->Add(Thotmasss);


  
 


  TCanvas *c1 = new TCanvas("c1","step1",1200,600);
  c1->Divide(2,1); 
  c1->cd(1);
  hpt->Draw();
  hpt->GetXaxis()->SetTitle("Jet Pt GeVc^{-1}");
  
  c1->cd(2);
  hm1->Draw();
  hm1->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}"); 
  c1->Update();
  c1->SaveAs("ptcut.png");
  
  TCanvas *c2 = new TCanvas("c2","step2",1200,600);
  c2->Divide(2,1); 
  c2->cd(1);
  ht31->Draw();
  ht31->GetXaxis()->SetTitle("#tau_3/#tau_1");

  c2->cd(2);
  hm2->Draw();
  hm2->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}"); 
   c2->Update();
 
 c2->SaveAs("ht31.png");
  
  /* 
  TCanvas *c3 = new TCanvas("c3","step2",1200,600);
  c3->Divide(2,1); 
  c3->cd(1);
  hhasphos->Draw();
  hhasphos->GetXaxis()->SetTitle("Has Photon Pt > 20 GeVc^{-1}");
  
  c3->cd(2);
  hm3->Draw();
  hm3->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}"); 
  c3->SaveAs("hasphos.png");
  */
  
  TCanvas *c4 = new TCanvas("c4","step2",1200,600);
  c4->Divide(2,1); 
  c4->cd(1);
  hphos->Draw();
  hphos->GetXaxis()->SetTitle("Pt_{#gamma}/Pt_{subjet}");
  
  c4->cd(2);
  hm4->Draw();
  hm4->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}"); 
   c4->Update();
 
  c4->SaveAs("phos.png");
  
  
  TCanvas *c5 = new TCanvas("","",1200,800);
  c5->Divide(4,2);
  c5->cd(1);
  
  c5->cd(1);
  c5->cd(1);
  c5->cd(1);
  c5->cd(1);
  c5->cd(1);
  

  c5->SaveAs("HTplots.png");
  
  TCanvas *c6 = new TCanvas("c6","",1000,1000);
  c6->Divide(2,2);
  c6->cd(1)->SetLogy();
  nj3l->Draw();
  nj3l->GetXaxis()->SetTitle("Njets Loose per event"); 

  c6->cd(2)->SetLogy();
  nj3t->Draw();
  nj3t->GetXaxis()->SetTitle("Njets Tight per event"); 


  c6->cd(3)->SetLogy();
  nj4l->Draw();
  nj4l->GetXaxis()->SetTitle("Njets Loose per event"); 
 
 

  c6->cd(4)->SetLogy();
  nj4t->Draw();
  nj4t->GetXaxis()->SetTitle("Njets Tight per event"); 
 
  c6->Update();
  c6->SaveAs("NjTL.png");



  TCanvas *c7 = new TCanvas("c7","",1000,500);
  c7->Divide(2,1);
  c7->cd(1);
  nj4l2m->Draw();
  nj4l2m->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}");

  c7->cd(2);
  nj4T2m->Draw();
  nj4T2m->GetXaxis()->SetTitle("Jet Prunned Mass GeVc^{-2}");


  c7->SaveAs("PrnM_sel.png");

 
 
  

}
Example #9
0
void plot_histograms()
{
   gROOT->Reset();
   gROOT->SetStyle("Plain");
   gROOT->LoadMacro("./get_th1f.C");

   TH1F* hecore;
   TH1F* hecores;
   TH1F* hecore_first;
   TH1F* hecore_second;
   TH1F* hecore_seconds;
   TH1F* hecore_secondt;
   TH1F* hecore_secondts;

   TFile* finput = new TFile("../../data/histograms/h.sii.ln2o.root");
   //TFile* finput = new TFile("histograms/h.susie.k1.root");
   //TFile* finput = new TFile("histograms/h.si.k1.root");
   //TFile* finput = new TFile("histograms/h.siii.g2.root");
   //   TFile* finput = new TFile("histograms/h.siii.feb2010.root");
   finput->cd();
   hecore = (TH1F*) get_th1f("hecore")->Clone();
   hecores = (TH1F*) get_th1f("hecores")->Clone();
   hecore_first = (TH1F*) get_th1f("hecore_first")->Clone();
   hecore_second = (TH1F*) get_th1f("hecore_second")->Clone();
   hecore_seconds = (TH1F*) get_th1f("hecore_seconds")->Clone();
   hecore_secondt = (TH1F*) get_th1f("hecore_secondt")->Clone();
   hecore_secondts = (TH1F*) get_th1f("hecore_secondts")->Clone();
//   hecore->Rebin(10);

   hecore->Rebin(10);
   hecores->Rebin(10);

   hecore_first->Rebin(100);
   hecore_second->Rebin(100);
   hecore_seconds->Rebin(100);
   hecore_secondt->Rebin(100);
   hecore_secondts->Rebin(100);

   TCanvas* c1 = new TCanvas("c1","c1",10,10,900,600);
   c1->cd(); gPad->SetLogy();
   hecore->GetXaxis()->SetTitle("Ecore [keV]");
   hecore->GetYaxis()->SetTitle("Entries/10keV");
   hecore->Draw();
   hecores->SetLineColor(kRed);
   //hecores->SetFillColor(kRed);
   hecores->Draw("same");
   TLegend* lone = new TLegend(0.5,0.5,0.85,0.75);
   lone->SetFillStyle(0);
   lone->AddEntry(hecore,"all events", "l");
   lone->AddEntry(hecores,"single-segment events", "l");
   lone->Draw();
   c1->Update();
   c1->Print("../../data/plots/siio/ecore_ss.eps");


   TCanvas* c2 = new TCanvas("c2","c2",10,10,900,600);
   c2->cd();
   hecore_first->Draw();
   c2->Update();

   TCanvas* c3 = new TCanvas("c3","c3",10,10,900,600);
   c3->cd(); gPad->SetLogy();
   hecore_second->SetTitle("second event");
   hecore_second->GetXaxis()->SetTitle("Ecore [keV]");
   hecore_second->GetYaxis()->SetTitle("Entries/100keV");
   hecore_second->SetLineWidth(2);
   hecore_second->SetMinimum(0.1);
   hecore_second->Draw();
   //hecore_seconds->SetLineColor(kRed);
   //hecore_seconds->SetFillColor(kRed);
   //hecore_seconds->Draw("same");
   hecore_secondt->SetLineColor(kBlue);
   hecore_secondt->SetLineWidth(2);
   hecore_secondt->Draw("same");
   hecore_secondts->SetLineColor(kRed);
   hecore_secondts->SetLineWidth(2);
   hecore_secondts->Draw("same");
   TLegend* ltwo = new TLegend(0.4,0.5,0.85,0.75);
   ltwo->SetFillStyle(0);
   ltwo->AddEntry(hecore_second,"Bi214 consecutive events","l");
   ltwo->AddEntry(hecore_secondt,"5x164 #mus time window","l");
   ltwo->AddEntry(hecore_secondts,"5x164 #mus and single-segment","l");
   ltwo->Draw();
   c3->Update();
   c3->Print("../../data/plots/siio/ecore_bi214.eps");

}
Example #10
0
//================================================
void DeltaZVsPos(const Int_t save = 0)
{
  THnSparseF *hn = (THnSparseF*)f->Get(Form("mhTrkDzDy_%s",trigName[kTrigType]));
  TList *list = new TList;

  // dz vs BL
  TH2F *hTrkDzVsBL = (TH2F*)hn->Projection(1,3);
  c = draw2D(hTrkDzVsBL,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType]));
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_BL_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType]));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_BL_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType]));
    }

  list->Clear();
  TString legName[30];
  TH1F *hTrkDzInBL[30];
  Int_t counter = 0;
  for(Int_t i=0; i<30; i++)
    {
      hTrkDzInBL[i] = (TH1F*)hTrkDzVsBL->ProjectionY(Form("hDeltaZ_BL%d",i+1),i+1,i+1);
      if(hTrkDzInBL[i]->GetEntries()>0)
	{
	  legName[counter] = Form("Module %d",i+1);
	  hTrkDzInBL[i]->SetLineColor(color[counter]);
	  list->Add(hTrkDzInBL[i]);
	  counter ++;
	}
    }
  c = drawHistos(list,"TrkDzInBL",Form("%s: #Deltaz of matched track-hit pairs in backleg;#Deltaz (cm)",trigName[kTrigType]),kTRUE,-100,100,kTRUE,0,1.2*hTrkDzInBL[1]->GetMaximum(),kFALSE,kTRUE,legName,kTRUE,"",0.15,0.25,0.2,0.88,kFALSE,0.04,0.04,kFALSE,1,kTRUE,kFALSE);
  TLine *line = GetLine(0,0,0,1.1*hTrkDzInBL[1]->GetMaximum(),1);
  line->Draw();
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_BL_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType]));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_BL_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType]));
    }

  // dz vs Mod
  TH2F *hTrkDzVsMod = (TH2F*)hn->Projection(1,4);
  c = draw2D(hTrkDzVsMod,Form("%s: #Deltaz of matched track-hit pairs",trigName[kTrigType]));
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_Mod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType]));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_vs_Mod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType]));
    }

  TH1F *hMthMod = (TH1F*)hTrkDzVsMod->ProjectionX("hMthMod");
  hMthMod->Sumw2();
  hMthMod->Scale(1./hMthMod->Integral());
  TH2F *hMtdHitMap = (TH2F*)f->Get(Form("mhMtdHitMap_%s",trigName[kTrigType]));
  TH1F *htmp = (TH1F*)hMtdHitMap->ProjectionY("hHitMod_finebin");
  htmp->Rebin(12);
  TH1F *hMtdHitMod = new TH1F(Form("hMtdHitMod_%s",trigName[kTrigType]),"# of MTD hits per module;module",5,1,6);
  for(int i=0; i<hMtdHitMod->GetNbinsX(); i++)
    {
      hMtdHitMod->SetBinContent(i+1,htmp->GetBinContent(i+1));
      hMtdHitMod->SetBinError(i+1,htmp->GetBinError(i+1));
    }
  hMtdHitMod->Scale(1./hMtdHitMod->Integral());
  list->Clear();
  list->Add(hMthMod);
  list->Add(hMtdHitMod);
  TString legName3[2] = {"Matched good hits","All good hits"};
  c = drawHistos(list,"MtdHitMod",Form("%s: MTD hits per module;module;probability",trigName[kTrigType]),kFALSE,0,5,kTRUE,0,0.5,kFALSE,kTRUE,legName3,kTRUE,"",0.15,0.25,0.6,0.88,kTRUE);
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sCompMtdHitMod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType]));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sCompMtdHitMod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType]));
    }

  list->Clear();
  TString legName2[5];
  TH1F *hTrkDzInMod[5];
  for(Int_t i=0; i<5; i++)
    {
      hTrkDzInMod[i] = (TH1F*)hTrkDzVsMod->ProjectionY(Form("hDeltaZ_Mod%d",i+1),i+1,i+1);
      legName2[i] = Form("Module %d",i+1);
      list->Add(hTrkDzInMod[i]);
    }
  c = drawHistos(list,"TrkDzInMod",Form("%s: #Deltaz of matched track-hit pairs in module;#Deltaz (cm)",trigName[kTrigType]),kTRUE,-100,100,kTRUE,0,1.2*hTrkDzInMod[3]->GetMaximum(),kFALSE,kTRUE,legName2,kTRUE,"",0.15,0.25,0.6,0.88,kTRUE);
  TLine *line = GetLine(0,0,0,hTrkDzInMod[3]->GetMaximum()*1.05,1);
  line->Draw();
  if(save) 
    {
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_Mod_%s.pdf",run_type,run_cfg_name.Data(),trigName[kTrigType]));
      c->SaveAs(Form("~/Work/STAR/analysis/Plots/%s/ana_Match/%sDeltaZ_in_Mod_%s.png",run_type,run_cfg_name.Data(),trigName[kTrigType]));
    }
}
Example #11
0
void plottingmacro()
{
 setTDRStyle();
 gROOT->ForceStyle();
 initOptions();

 std::vector<Sample> s = samples();
 Sample data(1,"fake data","S1.root",0,true,1000);

 for(size_t i=0;i< s.size();i++) if(s[i].data) {data=s[i];break;}
 data.file()->ls(); 
 for(size_t i=0;i< s.size();i++) s[i].dump(data.lumi());

 std::vector<std::string> names;

 TList * subs = data.file()->GetListOfKeys();
 for(size_t i=0;i< subs->GetSize();i++)
  {
    TList * objs = ((TDirectoryFile *) data.file()->Get(subs->At(i)->GetName()))->GetListOfKeys();
     for(size_t j=0;j< objs->GetSize();j++)
     {
         names.push_back(subs->At(i)->GetName()+std::string("/")  + objs->At(j)->GetName());
 //      std::cout << subs->At(i)->GetName() << "/"  << objs->At(j)->GetName() << std::endl;
         //TODO: select plots via regexp
     }
    
  }

 for(size_t i = 0 ; i < names.size() ; i++) 
  {
   std::map<std::string,TH1F *> grouped;
   TString n=names[i];
   if(!n.Contains(TRegexp("V.*RegionH.*mu.*HiggsMass"))) continue;
   TCanvas *c = new TCanvas();
   c->SetLogy(true);
   c->SetTitle(names[i].c_str());
   TH1F *hd = ((TH1F*)data.file()->Get(names[i].c_str()));
   Options o=options[names[i]];
   hd->Rebin(o.rebin);
   hd->SetMarkerStyle(21);
   hd->Draw("E1");
   hd->SetYTitle(o.yaxis.c_str());
   THStack * sta = new THStack("sta",hd->GetTitle());
   TLegend * l = new TLegend(o.legendx1,o.legendy1,o.legendx2,o.legendy2); //0.7,0.1,0.9,0.6);
  
   l->AddEntry(hd, "Data","LP");

   for(size_t j=0;j< s.size() ;j++) 
   { 
       if(!s[j].data) 
      {
       TH1F * h = ((TH1F*)s[j].file()->Get(names[i].c_str()));
       h->Scale(s[j].scale(data.lumi()));
       h->SetLineColor(s[j].color);
       h->SetFillColor(s[j].color);
       h->Rebin(options[names[i]].rebin);
       if(grouped.find(s[j].name)==grouped.end()) {
          grouped[s[j].name]=(TH1F *)h->Clone(("_"+names[i]).c_str());
          l->AddEntry(h,s[j].name.c_str(),"F");
       }
       else
       {
        grouped[s[j].name]->Add(h);
       }
       sta->Add(h);
//     h->Draw("same");
      }
   }
   sta->Draw("same");
   hd->Draw("E1same");
   hd->GetYaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max);
   l->Draw();


   std::cout << names[i] << " d: " <<  hd->Integral() << " ";
   THStack * sta2 = new THStack("sta2",hd->GetTitle());
   float tot=0;
   float toterr2=0;

   for(std::map<std::string,TH1F *>::iterator it = grouped.begin(); it != grouped.end();it++)
   {
             std::cout << it->first << " " << it->second->Integral() << " | " ;
             if(it->second->GetEntries() > 0) {
             float er=1.*sqrt(it->second->GetEntries())/it->second->GetEntries()*it->second->Integral();
             toterr2+=er*er;
             }
	     tot+=it->second->Integral();
             sta2->Add(it->second);
   }   
    std::cout << " Tot: " << tot << "+-" << sqrt(toterr2) <<  " SF: " << hd->Integral()/tot << std::endl;
    c = new TCanvas();
    sta2->Draw();
    hd->Draw("E1,same");
    sta2->GetYaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max);
    hd->GetYaxis()->SetRangeUser(options[names[i]].min,options[names[i]].max);
    l->Draw();

   

  }

}
Example #12
0
void singlejeteff(){


Double_t xbins[13] = {10,20,30,35,40,45,50,60,80,90,100,150,200};
int nbins = 12;

 TFile* g = new TFile("oct9/effoct11.root");
        g->TFile::Open();
          TH1F *h   = (TH1F*)g->Get("Denom");
	  h->Sumw2();
          h->Rebin(2,"hnew");




          TH1F *h20   = (TH1F*)g->Get("a4tt/hista4tt15");
          //h20->Sumw2();  h20->Rebin(nbins,"hnew20",xbins); 
          h20->Rebin(2,"hnew20");


          TH1F *h20h   = (TH1F*)g->Get("a4ttjes/hista4ttjes35");
          //h20h->Sumw2();  h20h->Rebin(nbins,"hnew20h",xbins); 
          h20h->Rebin(2,"hnew20h");

    
     
      
       TGraphAsymmErrors *h5=new TGraphAsymmErrors(hnew20,hnew);
         h5->Draw("AP");
         h5->SetMarkerStyle(20); //h5->SetMarkerSize(1.6);
         h5->SetMaximum(1.2); //to set the y axis maximum
         h5->SetMinimum(0.1); // to set the y axis minimum
         h5->GetXaxis()->SetRangeUser(0.,120.);
         h5->GetXaxis()->SetTitle("Leading jet p_{T,offline} (EM+JES) [GeV]");
         h5->GetYaxis()->SetTitle("Efficiency");


     
        TGraphAsymmErrors *h6=new TGraphAsymmErrors(hnew20h,hnew);
        h6->Draw("P,same");
        h6->SetMarkerStyle(22);h6->SetMarkerColor(2);h6->SetLineColor(2);h6->SetLineStyle(2);   



       

TPaveText *pt = new TPaveText(0.506182,0.4016529,0.75163,0.65,"blNDC");
   pt->SetBorderSize(0);
   pt->SetFillColor(0);
   pt->SetTextFont(42);
   pt->SetTextSize(0.05);            
   pt->AddText("| #eta_{offline} | <2.8");
   pt->Draw("same");




  TLegend *leg = new TLegend(0.506182,0.2016529,0.75163,0.4,"","brNDC");leg->SetFillColor(kWhite);  leg->SetBorderSize(0);
  leg->SetTextSize(0.05);
  leg->SetTextFont(42);
  leg->AddEntry(h5,"L2FS EM J15");    
  leg->AddEntry(h6,"L2FS EM+JES J35");  
  leg->SetBorderSize(0);
  leg->SetTextSize(0.05);   
  leg->SetTextFont(42);   
  leg->Draw("same");

         //c1->SetGridx();         c1->SetGridy();
                        //  c1->SetGridx();         c1->SetGridy();         //c1->SetLogx(1);
 //h6->Draw("HIST,C,same");h6->SetLineColor(2); 

       //c1->SetGridx();         c1->SetGridy();
  

          //TH1F *h5 = new TH1F("h5","L2FS_6j25  Efficiency",nbins,xbins);
         // TH1F *h5 = new TH1F("h5","L2FS_6j25  Efficiency",125,0,500);
         // h5->Divide(hnew20,hnew,1,1,"B");

}
Example #13
0
void plotFR_QCD(){

  gROOT->Reset();
  gROOT->SetStyle("Plain");
  gStyle->SetStatFormat("6.4f");
  gStyle->SetFitFormat("6.4f");
  int BoxValue = 11111111; //4680;  
  gStyle->SetOptFit(11);
  gStyle->SetOptDate(0);
  gStyle->SetOptTitle(0);
  //gStyle->SetOptStat(BoxValue);
  gStyle->SetOptStat(0);
  gStyle->SetPadBorderMode(0);
  gStyle->SetCanvasColor(0); //(10);
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetPadBottomMargin(0.15);
  gStyle->SetPalette(0);
  TPaveLabel pl;
  TLatex lt;
  lt.SetTextFont(70);
  lt.SetTextAlign(12);
  lt.SetTextSize(0.07);
  lt.SetTextColor(1);

  TPaveText* tText1 = new TPaveText(0.70, 0.90, 0.90, 0.95, "brNDC");
  tText1->SetBorderSize(0);
  tText1->SetFillColor(0);
  tText1->SetFillStyle(0);
  TText *t1 = tText1->AddText("(13 TeV)");
  tText1->SetTextSize(0.035);
  //tText1->Draw(); 
  //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  TPaveText* tText2 = new TPaveText(0.2, 0.90, 0.4, 0.95, "brNDC");
  tText2->SetBorderSize(0);
  tText2->SetFillColor(0);
  tText2->SetFillStyle(0);
  TText *t2 = tText2->AddText("CMS Spring15 Simulation");
  tText2->SetTextSize(0.035);
  //tText2->Draw(); 


  TLegend *leg = new TLegend(0.17, 0.77, 0.4, 0.85);
  leg->SetBorderSize(0.0);
  leg->SetMargin(0.3);
  leg->SetFillColor(0);
  leg->SetFillStyle(10);
  leg->SetLineColor(0);
  Float_t tsize2 = 0.03;
  leg->SetTextSize(tsize2); 

  
  TFile *_file0 = TFile::Open("ZprimetoMuMu-MC-CMSSW745_FR_QCD_25ns.root");
  

  TH1F *num; _file0->GetObject("h1_Num_Pt_w",num);
  TH1F *den; _file0->GetObject("h1_Den_Pt_w",den);

  TH1F *numMB; _file0->GetObject("h1_Num_Pt_Barrel_w",numMB);
  TH1F *denMB; _file0->GetObject("h1_Den_Pt_Barrel_w",denMB);

  TH1F *numME; _file0->GetObject("h1_Num_Pt_EndCap_w",numME);
  TH1F *denME; _file0->GetObject("h1_Den_Pt_EndCap_w",denME);

  
  double Nbins = num->GetNbinsX();
  cout << "Nbins=" << Nbins << endl;

  int nRebin=10;

  num->Rebin(nRebin);
  den->Rebin(nRebin);

  numMB->Rebin(nRebin);
  denMB->Rebin(nRebin);

  numME->Rebin(nRebin);
  denME->Rebin(nRebin);


  // 
  TH1F *fake=new TH1F("fake","fake",Nbins/nRebin,0.,2000.);
  TH1F *fakeMB=new TH1F("fakeMB","fakeMB",Nbins/nRebin,0.,2000.);
  TH1F *fakeME=new TH1F("fakeME","fakeME",Nbins/nRebin,0.,2000.);
   
  cout << "Bins=" << Nbins/nRebin << endl;

  int* arraysize = new int[1];
  arraysize[0]=Nbins/nRebin;
  Float_t xMB[arraysize[0]],yMB[arraysize[0]],exlMB[arraysize[0]],exhMB[arraysize[0]],eylMB[arraysize[0]],eyhMB[arraysize[0]];


  for (unsigned int i=1; i<=Nbins/nRebin;i++){
    // All Muon
    if (denMB->GetBinContent(i)>0.) {
      fakeMB->SetBinContent(i,double(numMB->GetBinContent(i)/denMB->GetBinContent(i)));

      xMB[i-1]=fakeMB->GetBinCenter(i);
      yMB[i-1]=fakeMB->GetBinContent(i);
      exlMB[i-1]=0.;
      exhMB[i-1]=0.;
      //eyhMB[i-1]=+0.5 + sqrt(fakeMB->GetBinContent(i)+0.25);
      //eylMB[i-1]=-0.5 + sqrt(fakeMB->GetBinContent(i)+0.25); 
      
      if (double(numMB->GetBinContent(i)/denMB->GetBinContent(i))<1.){
	fakeMB->SetBinError(i, sqrt( double(numMB->GetBinContent(i)/denMB->GetBinContent(i))*(1-double(numMB->GetBinContent(i)/denMB->GetBinContent(i)))/double(denMB->GetBinContent(i)) ) );}
      else fakeMB->SetBinError(i, sqrt( double(numMB->GetBinContent(i)/pow(denMB->GetBinContent(i),2)+1./pow(denMB->GetBinContent(i),3))));
      eyhMB[i-1]=fakeMB->GetBinError(i)/2.;
      eylMB[i-1]=fakeMB->GetBinError(i)/2.;      
    }
    else {
      fakeMB->SetBinContent(i,0.);
      fakeMB->SetBinError(i,0.);
      xMB[i-1] = 0.;
      eylMB[i-1] = 0.;
      eyhMB[i-1] = 0.;
      exlMB[i-1]=0.;
      exhMB[i-1]=0.;
    }

  }
 
  //TGraphAsymmErrors *grMB = new TGraphAsymmErrors(Nbins/nRebin,xMB,yMB,exlMB,exhMB,eylMB,eyhMB);
  TGraphAsymmErrors *grMB = new TGraphAsymmErrors();
  grMB->BayesDivide(numMB,denMB);

  //TGraphAsymmErrors *grMB = new TGraphAsymmErrors(numMB,denMB);
  grMB->SetMarkerColor(2);
  grMB->SetMarkerStyle(20);
  grMB->SetMarkerSize(0.95);

  //TF1* fn1 = new TF1("fn1","pol1",10,100);
  //fn1->SetLineColor(1);
  //grMB->Fit("fn1","R,smaes");

  //TF1* fn2 = new TF1("fn2",FittingFunc1,100,2000.0,3);
  //fn2->SetLineColor(1);
  //grMB->Fit("fn2","R");


  // ME
  Float_t xME[arraysize[0]],yME[arraysize[0]],exlME[arraysize[0]],exhME[arraysize[0]],eylME[arraysize[0]],eyhME[arraysize[0]];

  for (unsigned int i=1; i<=Nbins/nRebin;i++){
    // All Muon                                                                                                                                                                            
    if (denME->GetBinContent(i)>0.) {
      fakeME->SetBinContent(i,double(numME->GetBinContent(i)/denME->GetBinContent(i)));

      xME[i-1]=fakeME->GetBinCenter(i);
      yME[i-1]=fakeME->GetBinContent(i);
      exlME[i-1]=0.;
      exhME[i-1]=0.;
      //eyhME[i-1]=+0.5 + sqrt(fakeME->GetBinContent(i)+0.25);                                                                                                                               
      //eylME[i-1]=-0.5 + sqrt(fakeME->GetBinContent(i)+0.25);                                                                                

      if (double(numME->GetBinContent(i)/denME->GetBinContent(i))<1.){
        fakeME->SetBinError(i, sqrt( double(numME->GetBinContent(i)/denME->GetBinContent(i))*(1-double(numME->GetBinContent(i)/denME->GetBinContent(i)))/double(denME->GetBinContent(i)) ) );
      }
      else fakeME->SetBinError(i, sqrt( double(numME->GetBinContent(i)/pow(denME->GetBinContent(i),2)+1./pow(denME->GetBinContent(i),3))));
      eyhME[i-1]=fakeME->GetBinError(i)/2.;
      eylME[i-1]=fakeME->GetBinError(i)/2.;
    }
    else {
      fakeME->SetBinContent(i,0.);
      fakeME->SetBinError(i,0.);
      xME[i-1] = 0.;
      eylME[i-1] = 0.;
      eyhME[i-1] = 0.;
      exlME[i-1]=0.;
      exhME[i-1]=0.;
    }

  }


  //TGraphAsymmErrors *grME = new TGraphAsymmErrors(Nbins/nRebin,xME,yME,exlME,exhME,eylME,eyhME);  
  TGraphAsymmErrors *grME = new TGraphAsymmErrors();
  grME->BayesDivide(numME,denME);

  grME->SetMarkerColor(4);
  grME->SetMarkerStyle(20);
  grME->SetMarkerSize(0.95);
  

  
  TH2F *hframe=NULL,*hframe2=NULL; 
  hframe= new TH2F("hframe","hframe",500,50.,2000.,500,0.0001,2.0);
  hframe->GetYaxis()->SetTitle("Fake rate");
  hframe->GetXaxis()->SetTitle("p_{T} (GeV)");
  hframe->GetXaxis()->SetTitleOffset(1.7);
  hframe->GetYaxis()->SetTitleOffset(1.7);

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

  c1->SetLogy(1);
  c1->SetLogx(1);
  //c1->SetGrid();
  
  gPad->SetTopMargin(0.12);
  gPad->SetLeftMargin(0.15);
  gPad->SetFillColor(0);
  gPad->SetTickx();
  gPad->SetTicky();
  // gPad->SetGridy();
  //gPad->SetGridx();
    
  c1->SetLogy(1);
  c1->SetLogx(1);
  // c1->SetGrid();
  
  grMB->SetLineColor(1);
  grMB->GetXaxis()->SetTitleOffset(1.7);
  grMB->GetYaxis()->SetTitleOffset(1.7);
  grMB->GetXaxis()->SetLabelSize(0.03);
  grMB->GetYaxis()->SetLabelSize(0.03);
  grMB->GetXaxis()->SetTitle("p_{T} (GeV)");
  grMB->GetYaxis()->SetTitle("Fake rate");
  grMB->GetXaxis()->SetTitleOffset(1.5);
  grMB->GetYaxis()->SetTitleOffset(2.0);
  grMB->GetXaxis()->SetTitleSize(0.05);
  grMB->GetXaxis()->SetLabelSize(0.03);
  grMB->GetYaxis()->SetLabelSize(0.03);
  leg->AddEntry(grMB,"barrel","p");

  grME->SetLineColor(1);
  grME->GetXaxis()->SetTitleOffset(1.7);
  grME->GetYaxis()->SetTitleOffset(1.7);
  grME->GetXaxis()->SetLabelSize(0.03);
  grME->GetYaxis()->SetLabelSize(0.03);
  grME->GetXaxis()->SetTitle("p_{T} (GeV)");
  grME->GetYaxis()->SetTitle("Fake rate");
  grME->GetXaxis()->SetTitleOffset(1.5);
  grME->GetYaxis()->SetTitleOffset(2.0);
  grME->GetXaxis()->SetTitleSize(0.05);
  grME->GetXaxis()->SetLabelSize(0.03);
  grME->GetYaxis()->SetLabelSize(0.03);
  leg->AddEntry(grME,"endcap","p");

  hframe->Draw();
  grMB->Draw("Psame");
  grME->Draw("Psame");
  tText1->Draw("same");
  tText2->Draw("same");
  leg->Draw("same");
  
  c1->SaveAs("FR_QCD.png");
  c1->SaveAs("FR_QCD.pdf");
  c1->SaveAs("FR_QCD.eps");
  //c1->SaveAs("FR_QCD.root");

  TFile *fileX = new TFile("FR_QCD.root", "RECREATE");
  fileX->cd();
  numMB->Write();
  denMB->Write();
  numME->Write();
  denME->Write();
  //grMB->Write();
  //grME->Write();
  fileX->Write();
  fileX->Close();


}   
Example #14
0
int main ( int argc, char *argv[] )
{

  StopStyle();
  std::vector<std::string> vDec;
  //vDec.push_back("PhaseI");
  //vDec.push_back("PhaseII3");
  //vDec.push_back("PhaseII4");

  vDec.push_back("PhaseI_0PU");
  vDec.push_back("PhaseI_140PU");
  vDec.push_back("PhaseII3_140PU");
  vDec.push_back("PhaseII4_140PU");


  std::vector<std::string> vLep;
  vLep.push_back("EleEta");
  //vLep.push_back("ElePt");
  vLep.push_back("MuonEta"); 
  //vLep.push_back("MuonPt");
  //vLep.push_back("TauEta"); 
  //vLep.push_back("TauPt");
  //vLep.push_back("JetEta"); 
  //vLep.push_back("JetPt");
  //vLep.push_back("JetPt");
  //vLep.push_back("MET");
  //vLep.push_back("MHT");

    int cut = 0;
    //int cut = 5; //Before lepton veto
    //int cut = 14; //After METCut
  std::vector<int> VColor;
  VColor.push_back(1);
  VColor.push_back(2);
  VColor.push_back(4);
  VColor.push_back(6);
  VColor.push_back(kGreen+2);
  VColor.push_back(kOrange+9);
  VColor.push_back(60);


  TCanvas *c1 = new TCanvas("fd", "dfdf", 600, 500);
  TLegend *lg = NULL;
  //c1->SetGridx();
  //c1->SetGridy();

  for (int j = 0; j < vLep.size(); ++j)
  {
    if (vLep.at(j).find("Pt") != std::string::npos)
      lg = new TLegend(0.602349,0.1631356,0.8389262,0.4576271,NULL,"brNDC");
    else if (vLep.at(j).find("EleEta") != std::string::npos )
      //lg = new TLegend(0.3691275,0.1751055,0.6057047,0.4683544,"W(e#nu) + jets","brNDC");
      lg = new TLegend(0.3238255,0.1673729,0.5486577,0.4618644,"W(e#nu) + jets","brNDC");
    else if (vLep.at(j).find("MuonEta") != std::string::npos)
      //lg = new TLegend(0.3691275,0.1751055,0.6057047,0.4683544,"W(#mu#nu) + jets","brNDC");
      lg = new TLegend(0.3238255,0.1673729,0.5486577,0.4618644,"W(#mu#nu) + jets","brNDC");

      //lg = new TLegend(0.3791946,0.1737288,0.6157718,0.4682203,NULL,"brNDC");
    else if (vLep.at(j).find("JetEta") != std::string::npos)
      lg = new TLegend(0.3657718,0.7139831,0.6241611,0.9533898,NULL,"brNDC");
    else if (vLep.at(j).find("TauEta") != std::string::npos)
      lg = new TLegend(0.3842282,0.654661,0.6208054,0.9491525,NULL,"brNDC");
    else
      lg = new TLegend(0.3791946,0.1737288,0.6157718,0.4682203,NULL,"brNDC");


    //else if (vLep.at(j).find("EleEta") != std::string::npos)
    lg->SetBorderSize(0);
    lg->SetFillStyle(0); //transparent hollow?
    lg->SetTextFont(62); 
    //lg->SetTextSize(0.03);
    lg->SetTextSize(0.04);

    double ymin = 0.0;
    double ymax = 0.0;
    TAxis *yaxis = NULL;
    TAxis *xaxis = NULL;


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

      char pu[10];
      char det[10];
      sscanf(vDec.at(i).c_str(), "%[^_]_%s", det, pu);

      std::cout <<  " pu " << pu << "  "<< strcmp(pu, "0PU") << std::endl;

      std::string pileup ="" ;
      if (strcmp(pu, "0PU") == 0)  pileup = "NoPileUp";
      if (strcmp(pu, "50PU") == 0) pileup = "50PileUp";
      if (strcmp(pu, "140PU") == 0) pileup = "140PileUp";
      std::cout << " pileup " << pileup <<" dec " << det << std::endl;

      HTSample *HT = new HTSample("LPC_MHTCUT/", "Wlv*_14TEV_HT", pileup, det);
      HT->InitSample(3000*1000);
      c1->cd();
      c1->Update();

      TH1F* reco = NULL;
      TH1F* gen = NULL;
      //TH2D* reco = NULL;
      //TH2D* gen = NULL;


      std::cout << " " << vLep.at(j) << std::endl;
      if (vLep.at(j) != "MET" && vLep.at(j) != "MHT")
      {
        TString reconame = "AppMatched"+vLep.at(j);
        TString genname = "AppGen"+vLep.at(j);
        //reco = (TH2D*)HT->GetTH2D(reconame.Data(), cut);
        //gen = (TH2D*)HT->GetTH2D(genname.Data(), cut);
        reco = (TH1F*)HT->GetTH1(reconame.Data(), cut);
        gen = (TH1F*)HT->GetTH1(genname.Data(), cut);
      } else {
        //reco = (TH1F*)HT->GetTH1(vLep.at(j), cut);
        //gen = (TH1F*)HT->GetTH1("GenMet");
      }


      if (vLep.at(j).find("Pt") != std::string::npos)
      {
        reco->Rebin(5);
        gen->Rebin(5);
        
      }
      //TH1F* reco = (TH1F*)HT->GetTH1("JetEta", cut);
      //TH1F* gen = (TH1F*)HT->GetTH1("GenJetEta", cut);
      //TH1F* reco = (TH1F*)HT->GetTH1("MuonPt", cut);
      //reco->Rebin(5);
      //TH1F* gen = (TH1F*)HT->GetTH1("GenMuonPt", cut);
      //gen->Rebin(5);
      //TH1F* reco = (TH1F*)HT->GetTH1("ElePt", cut);
      //
      //TH1F* gen = (TH1F*)HT->GetTH1("GenElePt", cut);

      reco->Divide(gen);
      reco->SetTitle("");
      //gen->Draw();
      //gen->SetLineColor(1);
      reco->SetLineWidth(3);
      reco->SetLineColor(VColor.at(i));

      ymin = ymin < reco->GetMinimum() ? ymin : reco->GetMinimum();
      ymax = ymax > reco->GetMaximum() ? ymax : reco->GetMaximum();
      if (i == 0)
      {
        yaxis = reco->GetYaxis();
        xaxis = reco->GetXaxis();
        reco->Draw();
      }
      else
      {
        reco->Draw("same");
      }

      reco->GetYaxis()->SetTitle("Efficiency");

      if (vDec.at(i).find("PU") != std::string::npos)
      {

        std::cout << " vDec.at(i)" << vDec.at(i) << std::endl;
        std::cout<<"Run to \033[0;31m"<<__func__<<"\033[0m at \033[1;36m"<< __FILE__<<"\033[0m, line \033[0;34m"<< __LINE__<<"\033[0m"<< std::endl; 
        if (vDec.at(i) == "PhaseI_0PU")    
        {
          lg->AddEntry(reco, "Phase I, <PU>=0",   "fl");
          reco->SetLineColor(1);
        }
        if (vDec.at(i) == "PhaseI_140PU")  
        { 
          lg->AddEntry(reco, "Phase I, <PU>=140", "fl");
          reco->SetLineColor(4);
        }
        if (vDec.at(i) == "PhaseII3_140PU") 
        {
          lg->AddEntry(reco, "Phase II Conf3, <PU>=140", "fl");
          //lg->AddEntry(reco, "PhaseII3 <PU>=140", "fl");
          reco->SetLineColor(kGreen+2);
        }
        if (vDec.at(i) == "PhaseII4_140PU") 
        {
          lg->AddEntry(reco, "Phase II Conf4, <PU>=140", "fl");
          reco->SetLineColor(2);
        }


        //TString leg = vDec.at(i);
        //lg->AddEntry(reco, leg.ReplaceAll("_", " "), "l");
      }
      TString xlabel = reco->GetXaxis()->GetTitle();
      std::cout << xlabel << std::endl;
      if (xlabel =="#Pt_{Matched m} [GeV]") 
        std::cout<<"Run to \033[0;31m"<<__func__<<"\033[0m at \033[1;36m"<< __FILE__<<"\033[0m, line \033[0;34m"<< __LINE__<<"\033[0m"<< std::endl; 
      if (xlabel =="#eta_{Matched e}" ) xlabel = "#eta_{e}";
      if (xlabel =="#eta_{Matched m}" ) xlabel = "#eta_{#mu}";
      if (xlabel =="#eta_{Matched t}" ) xlabel = "#eta_{t}";
      if (xlabel =="#Pt_{Matched e} [GeV] " ) xlabel = "#P_{T}^{e} [GeV]";
      if (xlabel =="#Pt_{Matched m} [GeV] " ) xlabel = "#P_{T}^{#mu} [GeV]";
      if (xlabel =="#Pt_{Matched t} [GeV] " ) xlabel = "#P_{T}^{t} [GeV]";
      reco->GetXaxis()->SetTitle(xlabel);



      reco->GetYaxis()->SetTitleOffset(1.0);
      reco->GetXaxis()->SetTitleOffset(0.9);
      reco->GetYaxis()->SetTitleSize(0.06);
      reco->GetXaxis()->SetTitleSize(0.06);
      reco->GetYaxis()->SetLabelSize(0.05);
      reco->GetXaxis()->SetLabelSize(0.05);
      //reco->GetYaxis()->SetRangeUser(0.1*ymin, 5*ymax);
      //c1->Print("Pt.png");
      //c1->Print("MuonEta_0.png");
      //c1->Print("EleEta_0.png");
      //TH1F* jet = (TH1F*)HT->GetTH1("JetPTScale", cut);
      //jet->Draw();
      //c1->Print("Jet.png");

      delete HT;

    }

    yaxis->SetRangeUser(0.8*ymin, 1.2*ymax);
    xaxis->SetRangeUser(-4.5, 4.5);
    lg->Draw();
    DrawTitle();
    c1->RedrawAxis();

    std::stringstream ss;
    ss << "Efficiency_"<<vLep.at(j)<< "_"<< cut<< ".png";
    c1->Print(ss.str().c_str());
    ss.str("");
    ss << "Efficiency_"<<vLep.at(j)<< "_"<< cut<< ".pdf";
    c1->Print(ss.str().c_str());
    ss.str("");
    ss << "Efficiency_"<<vLep.at(j)<< "_"<< cut<< ".C";
    c1->Print(ss.str().c_str());
    ss.str("");
    ss << "Efficiency_"<<vLep.at(j)<< "_"<< cut<< ".root";
    c1->Print(ss.str().c_str());
  }

  return EXIT_SUCCESS;
}				// ----------  end of function main  ----------
Example #15
0
void PlotPubHisto(TObjArray histograms,TEnv *params){
    // This is a modification of the AddHistos macro
    
    // Number of histos to plot:
    Int_t ntot = histograms.GetEntries();
    
    // Check we have what we expect (the order should be: data, qcd, wjets, etc...)
    for(Int_t i = 0; i<ntot; i++){
	if(histograms[i]==0) {
	    cout<<"Error in AddHistos: histogram "<<i<<" is a NULL pointer!"<<endl;
	    return;
	}
	TH1F * hthis = (TH1F*) histograms[i];
	// include the overflow/underflow bins:
	int numbins = hthis->GetNbinsX(); //this is the last bin plotted
	double hicontent = hthis->GetBinContent(numbins);
	double overflow  = hthis->GetBinContent(numbins+1);// this bin contains the overflow
	double locontent = hthis->GetBinContent(1);// this is the first bin plotted
	double underflow = hthis->GetBinContent(0);// this bin contains the underflow
	if (underflow>0 || overflow>0){
	    //printf("%-20s numbins=%4i hicontent=%4.2f over=%4.2f locontent=%4.2f underflow=%4.2f \n",
	    //	 title.Data(),numbins,hicontent,overflow,locontent,underflow);
	}
	hthis->SetBinContent(numbins,hicontent+overflow);
	hthis->SetBinContent(1,locontent+underflow);
    }
    
    // define a few additional line styles:
    gStyle->SetLineStyleString(5,"20 12 4 12");
    gStyle->SetLineStyleString(6,"20 12 4 12 4 12 4 12");
    gStyle->SetLineStyleString(7,"20 20");
    gStyle->SetLineStyleString(8,"20 12 4 12 4 12");
    gStyle->SetLineStyleString(9,"80 25");
    gStyle->SetLineStyleString(10,"50 10 10 10");
    gStyle->SetLineStyleString(17,"30 25");
    gStyle->SetLineStyleString(20,"60 20");
    gStyle->SetLineStyleString(21,"60 20 20 20");
    int lineStyle[20];
    for(int i=0;i<20;i++) {
	lineStyle[i]=i;
    }

    // the first histogram in the list:
    TH1F *h0=((TH1F*) histograms[0])->Clone();
    
    // histogram output filename
    TString oFileName=params->GetValue("Histo.Output.Filename","bogus.eps");
    
    // figure out the number of signals
    Int_t nsig=1;
    if(params->Defined("Histo.Signal.Title.1")) nsig=1;
    if(params->Defined("Histo.Signal.Title.2")) nsig=2;
    if(params->Defined("Histo.Signal.Title.3")) nsig=3;
    
    cout << " I will use nsig = " << nsig << " signal sources" << endl;
    
    // Do the cumulative summing, except for the data
    TObjArray addedhistos; addedhistos.Clear();
    TObjArray signalhistos; signalhistos.Clear();
    TString sampletitles[20];
    Int_t nbkg=0;
    for(Int_t i = 1; i<ntot; i++){// i runs over histograms[i], so data is for i=0
	ostringstream baseSrcName;
	baseSrcName << "Files." << i+1 << ".";// Counting starts at 1: Files.1.Name: Data
	TString bSrcName(baseSrcName.str().c_str());
	// skip some if we want to show them as lines
	TString htitle=params->GetValue(bSrcName+"Title","");
	sampletitles[i-1]=htitle;
	if(params->GetValue("Histo.ShowSignalSeparately",0)==1 &&
	   // skip the last two if the signal title is not defined:
	   ( ( !(params->Defined("Histo.Signal.Title")||params->Defined("Histo.Signal.Title.1")) && i>=ntot-nsig) 
	     // skip the signal if the signal title is defined
	     || params->GetValue("Histo.Signal.Title",".")==htitle
	     || params->GetValue("Histo.Signal.Title.1",".")==htitle
	     || params->GetValue("Histo.Signal.Title.2",".")==htitle
	     || params->GetValue("Histo.Signal.Title.3",".")==htitle
	     ) ) {
	    TH1F * hthis = (TH1F*) histograms[i]->Clone();
	    cout<<" Found signal in location "<<i+1<<" with name "<<htitle.Data()<<endl;
	    signalhistos.Add(hthis);
	} else {
	    TH1F * hthis = (TH1F*) histograms[i]->Clone();
	    addedhistos.Add(hthis); // Fill in the new TObjArray with a copy 
	    //cout << " Adding bkg " << i << " " << htitle.Data() << " " << hthis->Integral() << endl;
	    // add all of the backgrounds
	    if (i>1) {// i=0 is the data, and we must start with the second
		      // background to add the previous
		TH1F * hprevious = (TH1F*) addedhistos[i-2];
		if ( hthis->GetXaxis()->GetNbins() != hprevious->GetXaxis()->GetNbins() ) {
		    // Protection against _whoran histogram. 
		    // We cannot add two histograms with different numbers of bins!
		    cout<<"Error in AddHistos: incompatible number of bins!"<<endl;  
		    return;
		}
		hthis->Add(hprevious); // Do the addition
		addedhistos.RemoveAt(i-1); // And substitute whatever we had 
		addedhistos.AddAt(hthis,i-1);
		nbkg++;
		//cout << "Substituing bkg " << i << " + " << i-1 << " in addedhistos["<< i-1 <<"]" << endl;
	    }	    
	} // end of: if adding histograms
    }
    cout << " nbkg = " << nbkg << endl; 
    
    // Rebin histos if necessary, but first calculate KS:
    TH1F *hbkg = (TH1F*) addedhistos[nbkg];
    double KS = h0->KolmogorovTest(hbkg);
    double chi2ndf = h0->Chi2Test(hbkg, "UWUFOFCHI2/NDF");
    //cout << title.Data() << " KS = " << KS << " chi2/NDF = " << chi2ndf << endl;
    // Rebin? Set nrebin = 0 to NOT do rebinning. 
    // Will rebin only histos whose maximum x axis value exceeds 20. 
    // Anything with less will most probably be already made of integers, so no
    // need to rebin that! 
    Int_t nbinsx = h0->GetXaxis()->GetNbins();
    Int_t nbinsy = 100;
    Int_t nrebin = 5;
    if ( nbinsx > 750 && nbinsx <= 1000) nrebin = 30;
    if ( nbinsx > 400 && nbinsx <= 750 ) nrebin = 25;//20
    if ( nbinsx > 300 && nbinsx <= 400 ) nrebin = 25;//15
    if ( nbinsx > 200 && nbinsx <= 300 ) nrebin = 25;//15
    if ( nbinsx > 150 && nbinsx <= 200 ) nrebin = 10;//10
    if ( nbinsx > 100 && nbinsx <= 150 ) nrebin = 10;//10
    if ( nbinsx > 50 && nbinsx <= 100 )  nrebin = 10;//10
    if ( nbinsx > 20 && nbinsx <= 50 )   nrebin = 2;
    if ( nbinsx <= 20 ) nrebin = 1;  
    
    printf(" Saw nbins =%4i, rebinning by nrebin =%2i to final %3i bins \n",nbinsx,nrebin,int(nbinsx/nrebin));	

    if ( nrebin != 0 ) {
	h0->Rebin(nrebin); // data
	for (Int_t i = 0; i<=nbkg; i++){
	    TH1F * h = (TH1F*) addedhistos[i];
	    h->Rebin(nrebin);
	}
	for (Int_t i = 0; i<nsig; i++){
	    TH1F * h = (TH1F*) signalhistos[i];
	    h->Rebin(nrebin);
	}
    }

    // default text size: 0.045
    // make it bigger for the paper
    float textSize = 0.045;
    if(params->GetValue("Histo.Preliminary","yes")==TString("paper")) textSize=0.07;
    if(params->Defined("Histo.TextSize")) textSize=params->GetValue("Histo.TextSize",0.07);
    
    // Now, check largest dimensions so that we can plot all histograms at once.
    Float_t xmin=9999., xmax=-9999., ymin=9999., ymax=-9999.;
    for(Int_t i = 0; i<=nbkg; i++){
	TH1F * h = (TH1F*) addedhistos[i];
	ostringstream baseSrcName;
	baseSrcName << "Files." << i+1 << ".";
	TString bSrcName(baseSrcName.str().c_str());
	
	TAxis *axis = h->GetXaxis();
	if( axis->GetXmin() < xmin ) xmin = axis->GetXmin();
	if( axis->GetXmax() > xmax ) xmax = axis->GetXmax();
	if( h->GetMinimum() < ymin ) ymin = h->GetMinimum();
	if( h->GetMaximum() > ymax ) ymax = h->GetMaximum();
    }
    ymax = TMath::Nint(ymax*1.25+1); // Make enough room for the big legend
    TString title = h0->GetTitle();
    
    //
    // now check if we should simply use the ranges that was passed to us.
    if(params->Defined("Histo.Xmin")) xmin = params->GetValue("Histo.Xmin",0.);
    if(params->Defined("Histo.Xmax")) xmax = params->GetValue("Histo.Xmax",0.);
    if(params->Defined("Histo.Ymin")) ymin = params->GetValue("Histo.Ymin",0.);
    if(params->Defined("Histo.Ymax")) ymax = params->GetValue("Histo.Ymax",0.);
    
    // Now make the frame:
    TH2F * frame = new TH2F("frame","",nbinsx,xmin,xmax,nbinsy,ymin,ymax);
    cout<<" frame has xmin "<<xmin<<", xmax "<<xmax<<", ymax "<<ymax<<endl;
    
    // get the x- and y-axis titles
    TString ytitle=params->GetValue("Histo.YTitle","");
    if ( params->Defined("Histo.XTitle")) {
	frame->SetXTitle(params->GetValue("Histo.XTitle",""));
    } else {
	frame->SetXTitle(h0->GetTitle());
    }
    frame->SetYTitle(ytitle.Data()); 
    // also set the text size for the X and Y axis titles and numbers
    // do this globally for the style we are using
    float axisLabelSize=textSize;
    frame->GetXaxis()->SetLabelSize(axisLabelSize);
    frame->GetYaxis()->SetLabelSize(axisLabelSize);
    frame->GetXaxis()->SetTitleSize(axisLabelSize);
    frame->GetYaxis()->SetTitleSize(axisLabelSize);
    
    frame->SetStats(false);
    // reduce the axis title offset if the fonts are very large
    if(textSize>0.055) frame->GetXaxis()->SetTitleOffset(1.0);
    // also change the X axis title offset to move it farther away from the numbers
    if(params->Defined("Histo.XTitle.Offset")) {
	float xtitoffset=params->GetValue("Histo.XTitle.Offset",1.0);
	frame->GetXaxis()->SetTitleOffset(xtitoffset);
    }
    
    // also change the y axis title offset to move it farther away from the numbers
    frame->GetYaxis()->SetTitleOffset(1.0);
    // reduce the axis title offset if the fonts are very large
    if(textSize>0.055) frame->GetYaxis()->SetTitleOffset(1.0);
    
    // set the axes divisions
    frame->GetXaxis()->SetNdivisions(505,true);
    if(params->Defined("Histo.XNdivisions")) frame->GetXaxis()->SetNdivisions(params->GetValue("Histo.XNdivisions",505),kTRUE);
    if(params->Defined("Histo.YNdivisions")) frame->GetYaxis()->SetNdivisions(params->GetValue("Histo.YNdivisions",505),kTRUE);
    
    // make sure the X axis title and Y axis title are in black!
    frame->GetXaxis()->SetTitleColor(1);
    frame->GetYaxis()->SetTitleColor(1);

    // Could plot in log scale...
    //gPad->SetLogy();

    // finally: Draw
    frame->Draw();
    
    // Draw the background ones:
    for(Int_t i=nbkg; i>=0; i--){
	TH1F * h = (TH1F*) addedhistos[i];
	h->SetStats(kFALSE);
	
	ostringstream baseSrcName;
	baseSrcName << "Files." << i+2 << ".";// to account for the data which is Files.1
	TString bSrcName(baseSrcName.str().c_str());
	Int_t hcolor=params->GetValue(bSrcName+"Color",1); 	
	h->SetLineColor(1);      
	h->SetFillColor(hcolor);
        if (i==nbkg) printf(" Data Yield = %5.2f ; SumBkg = %5.2f ; Data-SumBkg diff = %5.2f%% \n",
	   		     h0->Integral(),h->Integral(),(h0->Integral()-h->Integral())*100./h0->Integral());
	printf(" plotting bkg i=%2i name=%20.20s file=%2i integral=%5.1f color=%2i\n",
	       i,sampletitles[i].Data(),i+2,h->Integral(),hcolor);
	int fillStyle=params->GetValue(bSrcName+"FillStyle",1001);
	h->SetFillStyle(fillStyle);
	h->DrawCopy("Hist,Same");
    }
    //
    // and draw the signal ones
    // draw them in reverse order so that the last one will be on top.
    //for(Int_t i=ntot-3; i<ntot; i++){
    for(Int_t i=nsig-1; i>=0; i--){
	ostringstream baseSrcName;
	baseSrcName << "Files." << ntot+1-nsig+i << ".";
	TString bSrcName(baseSrcName.str().c_str());
	
	Int_t hcolor=params->GetValue(bSrcName+"Color",1);
	TH1F * h = (TH1F*) signalhistos[i];
       	if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=90"))        h->Add (h, 1.07874865  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=100"))  h->Add (h, 1.62317373  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=110"))  h->Add (h, 2.31347600  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=120"))  h->Add (h, 3.25275183  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=130"))  h->Add (h, 4.54142919  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=140"))  h->Add (h, 6.19195046  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=150"))  h->Add (h, 8.38307290  -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=160"))  h->Add (h, 11.31721008 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=170"))  h->Add (h, 14.85376469 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=180"))  h->Add (h, 19.54537459 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=190"))  h->Add (h, 25.44594010 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=200"))  h->Add (h, 32.94784356 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=220"))  h->Add (h, 54.09499080 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=240"))  h->Add (h, 86.85079034 -1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=260"))  h->Add (h, 136.31406761-1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=280"))  h->Add (h, 210.70375053-1.000);
	else if (sampletitles[ntot-1-nsig+i].Contains("m_{H}=300"))  h->Add (h, 319.79533099-1.000);
	
	printf(" plotting sig i=%2i name=%20.20s file=%2i integral=%5.1f color=%2i\n",
	       i,sampletitles[ntot-1-nsig+i].Data(),ntot+1-nsig+i,h->Integral(),hcolor);
	// create a white background around each line (helps readibility):
	TH1F *h1=h->Clone();
	h1->SetStats(kFALSE);
	h1->SetLineWidth(6);
	h1->SetLineColor(0);h1->SetFillColor(0);
	h1->SetLineStyle(1);
	h1->SetFillStyle(0);
	h1->Draw("HIST,SAME");
	// now draw the proper line:
	h->SetStats(kFALSE);
	h->SetLineWidth(6);
	h->SetLineColor(hcolor);h->SetFillColor(0);	
	Int_t hlinestyle = params->GetValue(bSrcName+"LineStyle",1);
	h->SetLineStyle(hlinestyle);
	h->SetFillStyle(0);	
	// finally, draw!
	h->Draw("HIST,SAME");      
    } // end of: drawing signal as separate lines
    
    // Data is special: 
    // change the default size of the little bar at the end of the error bar here
    gStyle->SetEndErrorSize(3);
    // also, maybe don't display the error bars along the X axis:
    //gStyle->SetErrorX(0);  // X error bars not displayed
    gStyle->SetErrorX(0.5);  // X error bars have width of a bin
    // now set the rest
    h0->SetMarkerSize(2);
    // if there are too many points (>80), keep the marker size smaller
    if(h0->GetNbinsX()>=50) h0->SetMarkerSize(1);
    //if(h0->GetNbinsX()>=100) h0->SetMarkerSize(1);
    h0->SetLineWidth(3);
    h0->SetMarkerStyle(8);
    h0->SetMarkerColor(1);
    h0->Draw("E1,SAME");
    
    // Print some comparison:
    //ostringstream basefactor;
    //basefactor << "Files." << nbkg+3 << "." << "Factor";
    //TString timesfactor(basefactor.str().c_str()); 
    //Double_t nprod = params->GetValue(timesfactor,1.000);
    //printf("Data Yield = %5.2f ; SumBkg = %5.2f ; SumBkg+Sig = %5.2f ; Data-SumBkg diff = %5.2f%% \n",
    //        h0->Integral(),hbkg2->Integral,(hbkg2->Integral()+(signalhistos[0]->Integral()/nprod),
    //        (h0->Integral()-hbkg2->Integral)*100./h0->Integral()));

    //
    // Print D0 and lumi:
    //
    TText *t1 = new TText();
    t1->SetTextFont(62);
    t1->SetTextColor(1);   
    t1->SetNDC();
    t1->SetTextAlign(12);
    t1->SetTextSize(textSize);
    TString prelim="D\328 Preliminary";
    if(oFileName.EndsWith(".eps")) {
	prelim="D\349 Preliminary L=3.7 fb^-1#";
    }
    else if(oFileName.EndsWith(".gif")) {
	prelim="D\328 Preliminary L=3.7 fb^-1#";
    }
    t1->DrawTextNDC(0.13,0.965,prelim.Data());

    // a counter of how much text we have added from the top
    int nAddTextLines=0;
    
    // any additional text?
    for(int iText=1;iText<20;iText++) {
	ostringstream baseTextName;
	baseTextName << "Histo.AddText." << iText;
	TString bTextName(baseTextName.str().c_str());
	if(params->Defined(bTextName)) {
	    // we are adding a line of text
	    TLatex *t2 = new TLatex();
	    t2->SetTextFont(62);
	    t2->SetTextColor(13);   
	    t2->SetTextAlign(32);
	    t2->SetNDC();
	    t2->SetTextSize(textSize);
	    TString addText(params->GetValue(bTextName,"."));
	    float x0=0.94;
	    float y0=0.96-(nAddTextLines)*0.05;
	    
	    // check if the user specified an alternative location for the text
	    if(params->Defined(bTextName+".X0")) x0=params->GetValue(bTextName+".X0",0.94);
	    if(params->Defined(bTextName+".Y0")) y0=params->GetValue(bTextName+".Y0",0.8);
	    if(params->Defined(bTextName+".TextSize")) t2->SetTextSize(params->GetValue(bTextName+".TextSize",textSize));
	    
	    // and increment the counter keeping track of how much we added,
	    // but only if the user didn't move the label around.
	    if(!params->Defined(bTextName+".X0")) nAddTextLines++;
	    printf("AddText %4.2f %4.2f %s\n",x0,y0,addText.Data());
	    
	    t2->DrawLatex(x0,y0,addText.Data()); 
	}
    }// end additional text
    
    // now draw the frame axis again so that we can see the tick marks
    frame->Draw("sameaxis");
    
    // Legend:
    TString showLegend(params->GetValue("Histo.ShowLegend","."));
    if( showLegend != "no" ){ 
	float lgdxmin=.65, lgdxmax=.90, lgdymin=.50, lgdymax=.91;
	if(showLegend=="yes" || showLegend=="right") {
	    
	} else if (showLegend=="left"){
	    lgdxmin=.16;
	    lgdxmax=.42;
	}
	TLegend *lgd = new TLegend(lgdxmin,lgdymin,lgdxmax,lgdymax); 
	// This line makes the legend transparent (not grey, ewwww!): 
	lgd->SetBorderSize(0); lgd->SetTextSize(textSize*0.9);// 10% less size 
	lgd->SetTextFont(62); lgd->SetFillColor(0);
	// Plot the legend in reverse order (but data goes first):
	NiceAddEntry(lgd,h0,params->GetValue("Files.1.Title","Data"),"PL");
	for(Int_t i = nbkg; i>=0; i--){
	    TH1F * h = (TH1F*) addedhistos[i];
	    TString lgd_entry= sampletitles[i]; // sampletitles runs from 0 (firstbkg) to ntot-1
	    NiceAddEntry(lgd,h,lgd_entry.Data(),"F");	
	}
	for(Int_t i = nsig-1; i>=0; i--){
	    TH1F * h = (TH1F*) signalhistos[i];
	    TString lgd_entry = sampletitles[i+nbkg+1]; // sampletitles runs from 0 (firstbkg) to ntot-1
	    ostringstream basefactor;
	    basefactor << "Files." << i+nbkg+3 << "." << "Factor";
	    TString timesfactor(basefactor.str().c_str());
	    Double_t nprod = params->GetValue(timesfactor,1.000);
	    if (nprod != 1.0 ) lgd_entry.Form("%s x%2.0f",lgd_entry.Data(),nprod);
	    //cout << i+nbkg+3 << " " << nprod << " " << lgd_entry.Data() << endl;
	    NiceAddEntry(lgd,h,lgd_entry.Data(),"L"); 
	}
	lgd->Draw("SAME");	
    }// show legend


    // Draw the KS:
    TLatex *ks = new TLatex();
    ks->SetTextFont(62);
    ks->SetTextColor(1);   
    TString ks_val = Form("KS = %3.2f",KS);
    ks->SetTextAlign(11); ks->SetTextSize(0.03); // ks->SetTextAngle(90); 
    ks->DrawTextNDC(0.83,0.93,ks_val.Data());
    TString chi2_val = Form("#chi^{2}/ndf = %3.1f",chi2ndf);
    ks->SetNDC(true); ks->DrawLatex(0.83,0.97,chi2_val.Data());
    //
    // Voila!
    //
}
void macro_MakeFRClosureTestRatio()
{
  // parameters //////////////////////////////////////////////////////////////
  // luminosity of data
  const float lumi = 3694;

  string inputFilePrefix = "invMassHistos";  // lumi and .root will be added
  //string inputFilePrefix = "test";

  // which closure test ratios should be plotted?
  bool plotClosureTest[4];
  plotClosureTest[0] = false;  // no corrections
  plotClosureTest[1] = false;  // GSF electrons not passing HEEP
  plotClosureTest[2] = false;  // all above + HEEP-GSF corrected with DY contribuion
  plotClosureTest[3] = true;  // all above + GSF-GSF corrected with W+jet and gamma+jet contribution

  // which histograms should be plotted?
  bool plotHisto[4];
  plotHisto[0] = true;  // EB-EB + EB-EE
  plotHisto[1] = true;  // EB-EB
  plotHisto[2] = true;  // EB-EE
  plotHisto[3] = true;  // EE-EE

  int font = 42;
  ////////////////////////////////////////////////////////////////////////////

//  const int rebin = 10;
  float massMin = 50;
  float massMax = 1500;
  int nBins = 1450;
  vector<pair<float, float> > binning;
  // VARIABLE BINNING
  binning.push_back(make_pair(100, 10));
  binning.push_back(make_pair(500, 25));
  binning.push_back(make_pair(1500, 250));
  // CONSTANT BINNING
//  binning.push_back(make_pair(massMax, 50));

  vector<float> bins;
  bins.push_back(massMin);
  for (vector<pair<float,float> >::iterator it = binning.begin(); it < binning.end(); ++it) {
    while (bins.back() < it->first)
      bins.push_back(bins.back() + it->second);
  }
  if (bins.back() < massMax)
    bins.push_back(massMax);
  nBins = bins.size() - 1;
  Double_t binArray[nBins + 1];
  for (int i = 0; i <= nBins; ++i)
    binArray[i] = (Double_t)bins.at(i);

  stringstream sStream;
  sStream << "Photon_Run2012A-PromptReco-v1+23May2012-v2+DoublePhotonHighPt_Run2012B_AOD_Cert_190456-195775_8TeV_PromptReco+May23ReReco_Collisions12_JSON_gct1_32_" << lumi << "pb-1";
  //sStream << lumi << "pb-1";
  TString folderDataHisto = sStream.str().c_str();
  // select histograms dynamically depending on state of correction //////////
  vector<TString> folderHeepGsfHisto;
  folderHeepGsfHisto.push_back(sStream.str().c_str());
  folderHeepGsfHisto.push_back(sStream.str().c_str());
  folderHeepGsfHisto.push_back("combinations");
  folderHeepGsfHisto.push_back("combinations");

  vector<TString> folderGsfGsfHisto;
  folderGsfGsfHisto.push_back(sStream.str().c_str());
  folderGsfGsfHisto.push_back(sStream.str().c_str());
  folderGsfGsfHisto.push_back(sStream.str().c_str());
  folderGsfGsfHisto.push_back("combinations");

  vector<TString> heepGsfHisto;
  heepGsfHisto.push_back("histoHeepGsfMassFR");
  heepGsfHisto.push_back("histoHeepGsfMassNoHeepFR");
  heepGsfHisto.push_back("histoHeepGsfCorr");
  heepGsfHisto.push_back("histoHeepGsfCorr");

  vector<TString> gsfGsfHisto;
  gsfGsfHisto.push_back("histoGsfGsfMassFR");
  gsfGsfHisto.push_back("histoGsfGsfMassNoHeepFR");
  gsfGsfHisto.push_back("histoGsfGsfMassNoHeepFR");
  gsfGsfHisto.push_back("histoGsfGsfCorr");
  ////////////////////////////////////////////////////////////////////////////

  vector<TString> canvasName;
  canvasName.push_back("ratioFR");
  canvasName.push_back("ratioFRNoHeep");
  canvasName.push_back("ratioFRCorrDY");
  canvasName.push_back("ratioFRCorrFull");

  vector<TString> canvasTitle;
  canvasTitle.push_back("Fake rate ratio GSF-GSF / HEEP-GSF - uncorrected");
  canvasTitle.push_back("Fake rate ratio GSF-GSF / HEEP-GSF - non HEEP");
  canvasTitle.push_back("Fake rate ratio GSF-GSF / HEEP-GSF - DY corrected");
  canvasTitle.push_back("Fake rate ratio GSF-GSF / HEEP-GSF - full corrected");

  vector<TString> acroSuffix;
  acroSuffix.push_back("");
  acroSuffix.push_back("BB");
  acroSuffix.push_back("BE");
  acroSuffix.push_back("EE");

  vector<TString> suffix;
  suffix.push_back("");
  suffix.push_back(" EB-EB");
  suffix.push_back(" EB-EE");
  suffix.push_back(" EE-EE");

  sStream.str("");
  sStream << inputFilePrefix << lumi << "pb-1.root";
  TFile input(sStream.str().c_str(), "read");
  input.cd();

  cout << endl << "Input file: " << sStream.str() << endl;

  // to keep the histogram when the file is closed
  TH1::AddDirectory(kFALSE);
  TH1::SetDefaultSumw2(kTRUE);
  
  for (unsigned int j = 0; j < 4; ++j) {
    if (!plotClosureTest[j]) continue;
    for (unsigned int p = 0; p < 4; ++p) {
      if (!plotHisto[p]) continue;
  
      TCanvas *c0 = new TCanvas(canvasName[j] + acroSuffix[p], canvasTitle[j] + suffix[p], 100, 100, 800, 600);
      c0->cd();
      c0->SetBorderMode(0);
      c0->SetFrameBorderMode(0);
      c0->SetFillColor(0);
      c0->SetFrameFillColor(0);
      gStyle->SetOptStat(0);
      gStyle->SetPadTickY(1);
  
      // get the histograms 
      input.cd(folderGsfGsfHisto[j]);
      TH1F *numHisto = (TH1F *)gDirectory->Get(gsfGsfHisto[j] + acroSuffix[p]);
      input.cd(folderHeepGsfHisto[j]);
      TH1F *denomHisto = (TH1F *)gDirectory->Get(heepGsfHisto[j] + acroSuffix[p]);
  
      TH1F *numHistoRebinned = (TH1F *)numHisto->Rebin(nBins, "numHistoRebinned" + acroSuffix[p], binArray);
      TH1F *denomHistoRebinned = (TH1F *)denomHisto->Rebin(nBins, "denomHistoRebinned" + acroSuffix[p], binArray);
  
      TH1F *ratioHisto = new TH1F("histoRatioCorr" + acroSuffix[p], canvasTitle[j] + suffix[p], nBins, binArray);
      ratioHisto->Divide(numHistoRebinned, denomHistoRebinned);
  
      ratioHisto->SetLineColor(4);
      ratioHisto->SetMarkerColor(4);
      ratioHisto->SetMarkerStyle(20);
  
      ratioHisto->Draw();
      ratioHisto->Fit("pol0", "+", "lep", 120, 500);
  
      sStream.str("");
      sStream << "#sqrt{s} = 7TeV,  #int L dt = " << lumi << "pb^{-1}";
      TPaveLabel *label0 = new TPaveLabel(0.6, 0.7, 0.9, 0.8, sStream.str().c_str(), "brNDC");
      label0->SetFillColor(0);
      label0->SetFillStyle(0);
      label0->SetBorderSize(0);
      label0->SetTextSize(0.30);
      label0->SetTextFont(font);
      label0->Draw("sames");
      TPaveLabel *label1 = new TPaveLabel(0.6, 0.8, 0.9, 0.9, "CMS preliminary", "brNDC");
      label1->SetFillColor(0);
      label1->SetFillStyle(0);
      label1->SetBorderSize(0);
      label1->SetTextSize(0.40);
      label1->SetTextFont(font);
      label1->Draw("sames");
  
      //TLegend *legend = new TLegend(0.38, 0.6, 0.53, 0.9);
      //legend->SetTextSize(0.03);
      //legend->SetTextFont(font);
      //legend->SetBorderSize(0);
      //legend->SetFillStyle(0);
      //legend->AddEntry(ratioHisto, "Ratio GSF-GSF / HEEP-GSF (non HEEP)", "lep");
      //legend->Draw("sames");

    } // end loop over eta ranges
  } // end loop over corrections
  input.Close();
}
void compareSherpaMadgraph(std::string sherpafile, std::string madgraphfile,
                           std::string var,
                           float xmin=-9999.0, float xmax=-9999.0,
                           bool logScale=false,
                           std::string output="test")
{

    setTDRStyle();
    gStyle->SetOptStat(0);

    TH1F* hsherpa;
    TH1F* hmadgraph;

    char tempName[300];


    // first get the histogram files
    TFile *fsherpa = TFile::Open(sherpafile.data());
    TFile *fmadgraph   = TFile::Open(madgraphfile.data());

    hsherpa  = (TH1F*)(fsherpa->Get(var.data()));
    hmadgraph    = (TH1F*)(fmadgraph->Get(var.data()));

    TH1D* hscale =(TH1D*) hsherpa->Clone("hscale");
    hscale->SetYTitle("SHERPA/MADGRAPH");

    int nREBIN=2;
    if(var.find("pt")!= std::string::npos)
        nREBIN=4;

    hsherpa->GetXaxis()->SetNdivisions(5);
    hsherpa->GetYaxis()->SetDecimals();
    hsherpa->Rebin(nREBIN);

    hmadgraph->GetXaxis()->SetNdivisions(5);
    hmadgraph->GetYaxis()->SetDecimals();
    hmadgraph->Rebin(nREBIN);

    hscale->GetXaxis()->SetNdivisions(5);
    hscale->GetYaxis()->SetDecimals();
    hscale->Rebin(nREBIN);

    hsherpa->SetLineColor(2);
    hsherpa->SetMarkerColor(2);
    hsherpa->SetMarkerSize(1);
    hsherpa->SetMarkerStyle(24);


    hmadgraph->SetLineColor(4);
    hmadgraph->SetMarkerColor(4);
    hmadgraph->SetMarkerSize(1);
    hmadgraph->SetMarkerStyle(21);

    // if normalizing to the same area, set the scale

    int binLo = -1;
    int binHi = -1;
    int nbins = hsherpa->GetNbinsX();
    if(xmin>-9999.0 && xmax>-9999.0)
    {

        binLo = hsherpa->FindBin(xmin);
        binHi = hsherpa->FindBin(xmax)-1;

    }

    else
    {
        binLo = 1;
        binHi = nbins;
        xmin = hsherpa->GetBinLowEdge(1);
        xmax = hsherpa->GetBinLowEdge(nbins+1);
    }


    //   float scale_mc = (float)hsherpa->Integral(binLo,binHi)/(float)hmadgraph->Integral(binLo,binHi);
    //   cout << "binLo = " << binLo << ", binHi = " << binHi << endl;
    //   cout << "xmin = " << xmin << "xmax = " << xmax << endl;

    //   hmadgraph->Sumw2();
    //   hmadgraph->Scale(scale_mc);

    float scale_sherpa   = 1000.0*4.890*3048.0/4.71644910071102437e+06;

    float scale_madgraph = 1000.0*4.890*3048.0/3.59644320000000000e+07;

    hsherpa->Sumw2();
    hsherpa->Scale(scale_sherpa);

    hmadgraph->Sumw2();
    hmadgraph->Scale(scale_madgraph);

    cout << "hmadgraph integral = " << hmadgraph->Integral() << endl;
    cout << "hsherpa integral = "   << hsherpa->Integral() << endl;;

    // get the ratio
    double chi2 = 0;
    int realbin = 0;
    for(int i=1; i<= nbins; i++) {

        double nmc=hmadgraph->GetBinContent(i);
        double ndata=hsherpa->GetBinContent(i);
        double nmcerr=hmadgraph->GetBinError(i);
        double ndataerr=hsherpa->GetBinError(i);

        if(nmc<0 || ndata<0)continue;

        if(nmcerr==0 && ndataerr==0)continue;

        if(nmc==0 && ndata==0)continue;

        double chi2ndef = (nmc-ndata)*(nmc-ndata)/
                          ( nmcerr*nmcerr+ ndataerr*ndataerr);
        chi2 += chi2ndef;
        realbin++;

        cout << "Bin " << i << " : " << ndata << ", " << nmc;
        cout << " " << chi2ndef << endl;


        // now calculate the ratio
        if(nmc==0 || nmcerr==0 || ndata==0 || ndataerr==0)continue;
        cout << "Bin " << i << " ratio = " << ndata/nmc << endl;
        hscale->SetBinContent(i,ndata/nmc);
        double err = 0;
        err=
            (ndata/nmc)*sqrt(pow(nmcerr/nmc,2)+pow(ndataerr/ndata,2));
        hscale->SetBinError(i,err);

    }


    hsherpa->GetXaxis()->SetRangeUser(xmin,xmax);
    hmadgraph->GetXaxis()->SetRangeUser(xmin,xmax);
    hscale->GetXaxis()->SetRangeUser(xmin,xmax);


    TCanvas* c1 = new TCanvas("c1","",700,1000);
    c1->Divide(1,2,0.01,0);
    c1->cd(1);
    if(logScale)
        gPad->SetLogy(1);
    gPad->SetTopMargin(0.01);
    gPad->SetBottomMargin(0);
    gPad->SetRightMargin(0.04);


    float max_data  = hsherpa->GetBinError(hsherpa->GetMaximumBin()) + hsherpa->GetMaximum();
    float max_mc    = hmadgraph->GetBinError(hmadgraph->GetMaximumBin()) + hmadgraph->GetMaximum();

    if(max_data > max_mc)
    {
        hsherpa->Draw("e");
        hmadgraph->Draw("hesame");
    }
    else
    {   hmadgraph->Draw("he");
        hsherpa->Draw("esame");
    }


    float x1NDC = 0.691;
    float y1NDC = 0.757;
    float x2NDC = 0.894;
    float y2NDC = 0.973;

    TLegend* leg = new TLegend(x1NDC,y1NDC,x2NDC,y2NDC);

    leg->SetFillColor(0);
    leg->SetFillStyle(0);
    leg->SetTextSize(0.04);
    leg->SetBorderSize(0);
    leg->AddEntry(hsherpa, "SHERPA");
    leg->AddEntry(hmadgraph, "MADGRAPH");
    leg->Draw("same");



    c1->cd(2);
    gStyle->SetStatW       (0.3);
    gStyle->SetStatH       (0.3);
    gStyle->SetStatX       (0.879447);
    gStyle->SetStatY       (0.939033);
    gStyle->SetStatFontSize(0.05);
    gStyle->SetStatBorderSize(0);
    gPad->SetRightMargin(0.04);
    gPad->SetTopMargin(0);
    gPad->SetBottomMargin(0.2);
    gPad->SetTickx();
    gStyle->SetOptFit(1);
    hscale->SetTitle("");
    hscale->SetMaximum(3.0);
    hscale->SetMinimum(-0.5);
    hscale->SetTitleOffset(1.2,"Y");
    hscale->Draw("e1");
    TF1* fline = new TF1("fline","pol1");
    TLine* l2 = new TLine(xmin,1.,xmax,1.);
    l2->SetLineColor(4);
    l2->SetLineStyle(3);
    fline->SetLineWidth(3);
    fline->SetLineColor(6);
    fline->SetNpx(2500);
    hscale->Fit("fline","","");
    l2->Draw("same");


    string dirName = "compareSherpaMadgraph";
    gSystem->mkdir(dirName.data());

    std::string filename;
    std::string psname = dirName + "/" + var;
    if(output !="test")
        psname = dirName+ "/" + output;
    else
        psname = dirName+ "/" + var;
    filename = psname + ".eps";
    c1->Print(filename.data());
    filename = psname + ".gif";
    c1->Print(filename.data());
    filename = psname + ".pdf";
    c1->Print(filename.data());
    //   c1->Close();
}
void HwwNoteFigs(TString filename = "../histo_tmva_new-ntuples-1_160_0.root",
                 int mass = 170, int ReBin = 4, int ysel = 0)
{
	TFile* infile = new TFile(filename.Data(),"READ");
	setTDRStyle(0);
	
	//BDTD dists
	TCanvas* c1 = new TCanvas("c1","c1",0,-200,500,500);
	
        TH1F* histoBg =  histo4->Clone();
        histoBg->Add(histo3);
        histoBg->Add(histo2);
        histoBg->Add(histo1);

    	TH1F* histo_4 =  histo4->Clone();
    	histo3->Add(histo_4);
    	TH1F* histo_3 =  histo3->Clone();
    	histo2->Add(histo_3);
    	TH1F* histo_2 =  histo2->Clone();
    	histo1->Add(histo_2);

        histo1->Rebin(ReBin);
        histo1->SetFillColor(kBlue);
        histo1->SetFillStyle(1001);
        histo1->SetLineStyle(0);
        histo1->SetLineWidth(0);

        histo2->Rebin(ReBin);
        histo2->SetFillColor(kMagenta);
        histo2->SetFillStyle(1001);
        histo2->SetLineStyle(0);
        histo2->SetLineWidth(0);

        histo3->Rebin(ReBin);
        histo3->SetFillColor(kGreen);
        histo3->SetFillStyle(1001);
        histo3->SetLineStyle(0);
        histo3->SetLineWidth(0);
        
        histo4->Rebin(ReBin);
        histo4->SetFillColor(kCyan);
        histo4->SetFillStyle(1001);
        histo4->SetLineStyle(0);
        histo4->SetLineWidth(0);

        char YTitle[300];
        sprintf(YTitle,"events / bin");
        char XTitle[300];
        sprintf(XTitle,"BDT Output");
    	histo0->SetYTitle(YTitle);
    	histo1->SetYTitle(YTitle);
    	histo2->SetYTitle(YTitle);
    	histo3->SetYTitle(YTitle);
    	histo4->SetYTitle(YTitle);

    	histo0->SetXTitle(XTitle);
    	histo1->SetXTitle(XTitle);
    	histo2->SetXTitle(XTitle);
    	histo3->SetXTitle(XTitle);
    	histo4->SetXTitle(XTitle);
    	histo1->SetTitleSize(0.05, "X");
    	histo1->GetXaxis()->SetTitleFont(62);
    	histo1->GetXaxis()->SetLabelFont(61);
    	histo1->GetYaxis()->SetLabelFont(61); 
    	histo1->GetYaxis()->SetTitleOffset(1.3);
    	histo1->SetLabelSize(0.04, "Y");
    	histo1->SetLabelSize(0.04, "X");

	int min = histoBg->FindBin(-1.5);
	int max = histoBg->FindBin(1.5);

	histoBg->GetXaxis()->SetRange(min,max);
	
	histoBg->SetMarkerStyle(20);
	histoBg->SetMarkerSize(1.0);
	histoBg->GetYaxis()->SetTitleOffset(1.40);
	
	histo0->SetMarkerStyle(21);
	histo0->SetMarkerSize(1.0);
	
	histoBg->Rebin(ReBin);
	histo0->Rebin(ReBin);

	histoBg->SetLineColor(4);
	histo0->SetLineColor(1);

	scaleHist(histoBg);
	scaleHist(histo0);
	cout << "bg events: " << histoBg->GetSumOfWeights() << endl;
	cout << "si events: " << histo0->GetSumOfWeights() << endl;

	histoBg->SetYTitle("Events");
    	histo1->SetMinimum(0.01);
	if(ysel == 0)  {
	  histo1->Draw("hist");
	}
	else          {
	  histo0->Draw("E");
	  histo1->Draw("hist,same");
    	}
	histo2->Draw("hist,same");
    	histo3->Draw("hist,same");
    	histo4->Draw("hist,same");
    	histo0->Draw("E, same");
	//histoBg->DrawCopy("hist");
	//histo0->DrawCopy("hist,same");

	TLegend* leg = new TLegend(0.63, 0.75, 0.92, 0.92);
	leg->SetFillColor(0);
	char theSLine[100];
	if(mass != 999)	sprintf(theSLine,"Signal, m_{H}=%d GeV",mass);
	else    	sprintf(theSLine,"WW");
        cout << theSLine << endl;
	leg ->AddEntry(histo0,theSLine);
    	leg ->AddEntry(histo4,"W+Jets, W#gamma","F"); 
    	leg ->AddEntry(histo3,"di-boson","F");  
    	leg ->AddEntry(histo2,"t#bar{t}, tW","F"); 
    	leg ->AddEntry(histo1,"Drell-Yan","F"); 
	leg->Draw("same");
	
        TString fileOutput1(filename.Data());
	TString theLine = "_";
	theLine = theLine + "plot.eps";
        fileOutput1.ReplaceAll(".root",theLine.Data());
        fileOutput1.ReplaceAll("../","");
        fileOutput1.ReplaceAll("rootfiles_fastsim/","");
        fileOutput1.ReplaceAll("rootfiles_fullsim/","");
	c1->SaveAs(fileOutput1.Data());
        //return;
	//--------------------------------
	TCanvas* c3 = new TCanvas("c3","c3",550,-200,500,500);
	c3->SetLogx();
	c3->SetLogy();
	gPad->SetGrid(1,1);
	TGraphErrors* gBDTD = makeGraphFromHists(histo0, histoBg);
	gBDTD->Draw("APXl");
	TH1* zBDTD = gBDTD->GetHistogram();
	zBDTD->SetXTitle("Signal Events");
	zBDTD->SetYTitle("Signal/Background");
	//zBDTD->SetYTitle("Background Events");
	//zBDTD->DrawCopy();

	TLegend* leg3 = new TLegend(0.7, 0.7, 0.9, 0.9);
	leg3->SetFillColor(0);
	leg3->AddEntry(gBDTD,theSLine,"lp");
	leg3->Draw("same");
        TString fileOutput2(filename.Data());
	theLine = "_";
	theLine = theLine + "counts.eps";
        fileOutput2.ReplaceAll(".root",theLine.Data());
        fileOutput2.ReplaceAll("../","");
        fileOutput2.ReplaceAll("rootfiles_fastsim/","");
        fileOutput2.ReplaceAll("rootfiles_fullsim/","");
	c3->SaveAs(fileOutput2.Data());
	
}
Example #19
0
void AllInOne_combineLepton(const std::string& dataset,int btag=0, double timesX=1, bool useNewShape=false){

  std::string useNewShapeText = (useNewShape) ? "_newshape" : "";

  char wsFileName[700];
  sprintf(wsFileName,"datacards/400/hzz2l2q_ee%db.input.root",btag);
  //sprintf(wsFileName,"PROVA/datacards_%s%s/hzz2l2q_ee%db.input.root",dataset.c_str(), useNewShapeText.c_str(),btag);

  gSystem->Load("libRooFit");
  gSystem->Load("libFFTW");

  string histoName[3];
  histoName[0]="mZZ_kinfit_hiMass_0btag";
  histoName[1]="mZZ_kinfit_hiMass_1btag";
  histoName[2]="mZZ_kinfit_hiMass_2btag";
  string btagName[3]={"0b","1b","2b"};

  double LumiScale=0.;
  if( dataset=="Run2011A_FULL" ) LumiScale = 2100.;
  else if( dataset=="LP11" ) LumiScale = 1600.;
  else {
    std::cout << "Unknown dataset '" << dataset << "'. Exiting." << std::endl;
  }

  RooDataSet *data_bkg;  
  RooDataSet *data_temp;
  TFile *file;

  string cutString[3];
  cutString[0]="nBTags==0 && (mZjj>75 && mZjj<105) && mZZ>183";
  cutString[1]="nBTags==1 && (mZjj>75 && mZjj<105) && mZZ>183";
  cutString[2]="nBTags==2 && (mZjj>75 && mZjj<105) && mZZ>183";

  int binWidth=20;
  int highBin=750;
  int lowBin=150;

//double muonEff[3]={.576,.548,.489};

//double expSig[3];
//expSig[0]=5.65*LumiScale ;
//expSig[1]=4.89*LumiScale ;
//expSig[2]=2.37*LumiScale ;

  char alphaFileName[200];
  sprintf( alphaFileName, "alphaFile_%s_%dbtag_ALL.root", dataset.c_str(), btag);
  TFile* alphaFile = TFile::Open(alphaFileName);
  TTree* treeSidebandsDATA_alphaCorr = (TTree*)alphaFile->Get("sidebandsDATA_alpha");
  TH1D* h1_mZZ_sidebands_alpha = new TH1D("mZZ_sidebands_alpha", "", 65, 150., 800.);
  char sidebandsCut_alpha[500];
  sprintf(sidebandsCut_alpha, "eventWeight_alpha*(isSidebands && nBTags==%d)", btag);
  treeSidebandsDATA_alphaCorr->Project("mZZ_sidebands_alpha", "mZZ", sidebandsCut_alpha);
  float expBkg = h1_mZZ_sidebands_alpha->Integral();
  std::cout <<  "++++ expBkg: " << expBkg << std::endl;



  stringstream convert;

  // --------------------- measurable (ZZ invariant mass) ----------------
  string temp;
  temp="m_{ZZ}";
  RooRealVar mZZ("mZZ",temp.c_str(),lowBin,highBin);
  RooRealVar nBTags("nBTags","nBTags",-1.,3.);
  RooRealVar leptType("leptType","leptType",0,1);
  RooRealVar mZjj("mZjj","mZjj",0,200.);

  // ----------------- get parameters from data cards! -----------------
  
  TFile *wsFile = new TFile(wsFileName);
  RooWorkspace *ws = (RooWorkspace*) wsFile->Get("w");

  // ==================== defining bkg PDF ==========================
  // ------------------------ fermi ------------------------------
  RooRealVar cutOff("cutOff","position of fermi",ws->var("cutOff_BKG")->getVal());
  cutOff.setConstant(kTRUE);
  RooRealVar beta("beta","width of fermi",ws->var("beta_BKG")->getVal());
  beta.setConstant(kTRUE);
	     		       
  RooFermi fermi("fermi","fermi function",mZZ,cutOff,beta);
  // -------------------- double gauss ---------------------------
  temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p1";
  RooRealVar m("m","m",ws->var(temp.c_str())->getVal());
  m.setConstant(kTRUE);
  temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p2";
  RooRealVar wdth("wdth","wdth",ws->var(temp.c_str())->getVal());
  wdth.setConstant(kTRUE);
  temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p3";
  RooRealVar n("n","n",ws->var(temp.c_str())->getVal());
  n.setConstant(kTRUE);
  temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p4";
  RooRealVar alpha("alpha","alpha",ws->var(temp.c_str())->getVal());
  alpha.setConstant(kTRUE);
  temp="CMS_hzz2l2q_bkg"+btagName[btag]+"p5";
  RooRealVar theta("theta","theta",ws->var(temp.c_str())->getVal());
  theta.setConstant(kTRUE);

  RooCB CB("CB","Crystal ball",mZZ,m,wdth,alpha,n,theta);
  
  RooProdPdf background("background","background",RooArgSet(fermi,CB));


  // ------------------ get data --------------------------
  // for reading sideband extrapolated data...
  std::string fileName = "HZZlljjRM_DATA_" + dataset + "_optLD_looseBTags_v2_ALL.root";
  file = new TFile(fileName.c_str());
  //file = new TFile("../HZZlljjRM_DATA_Run2011A_FULL_optLD_looseBTags_v2_ALL.root");
  TTree* t=(TTree*)file->Get("tree_passedEvents");
  data_bkg=new RooDataSet("data_bkg","data_bkg",t,
			  RooArgSet(mZZ,leptType,nBTags,mZjj),
			  cutString[btag].c_str());

  // --------- draw MC data -------------------
  RooPlot *plot_MCbkg = mZZ.frame(lowBin,highBin,(int)(highBin-lowBin)/binWidth);

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

  TPaveText* cmslabel = new TPaveText( 0.145, 0.953, 0.6, 0.975, "brNDC" );
  cmslabel->SetFillColor(kWhite);
  cmslabel->SetTextSize(0.038);
  cmslabel->SetTextAlign(11);
  cmslabel->SetTextFont(62);
  cmslabel->SetBorderSize(0);
  char lumilabel[500];
  sprintf( lumilabel, "CMS Preliminary 2011, %.1f fb^{-1}", LumiScale/1000.);
  cmslabel->AddText(lumilabel);

  TPaveText* label_sqrt = new TPaveText(0.7,0.953,0.96,0.975, "brNDC");
  label_sqrt->SetFillColor(kWhite);
  label_sqrt->SetTextSize(0.038);
  label_sqrt->SetTextFont(42);
  label_sqrt->SetTextAlign(31); // align right
  label_sqrt->SetBorderSize(0);
  label_sqrt->AddText("#sqrt{s} = 7 TeV");
  //-----------------------------------------------------------------------

  background.plotOn(plot_MCbkg,Normalization(expBkg));
  data_bkg->plotOn(plot_MCbkg,Binning((int)(highBin-lowBin)/binWidth));
  // -------------------- get histograms -----------------
  
  TFile *ZjetsFile = new TFile("HZZlljjRM_DYJetsToLL_TuneZ2_M-50_7TeV-madgraph-tauola_Summer11-PU_S4_START42_V11-v1_optLD_looseBTags_v2_ALL.root");
  TFile *TTFile = new TFile("HZZlljjRM_TT_TW_TuneZ2_7TeV-powheg-tauola_Summer11-PU_S4_START42_V11-v1_optLD_looseBTags_v2_ALL.root");
  TFile *VVFile = new TFile("HZZlljjRM_VV_TuneZ2_7TeV-pythia6-tauola_Summer11-PU_S4_START42_V11-v1_optLD_looseBTags_v2_ALL.root");
  TFile *H400File = new TFile("HZZlljjRM_GluGluToHToZZTo2L2Q_M-400_7TeV-powheg-pythia6_Summer11-PU_S4_START42_V11-v1_optLD_looseBTags_v2_ALL.root");

  TH1F *hZjets =(TH1F*)ZjetsFile->Get(histoName[btag].c_str());
  hZjets->SetName("hZjets");
  hZjets->Scale(LumiScale);
  hZjets->Rebin(binWidth);
  hZjets->SetFillColor(30);

  TH1F *hTT =(TH1F*)TTFile->Get(histoName[btag].c_str());
  hTT->SetName("hTT");
  convert << binWidth;
  temp=";m_{ZZ} [GeV]; Events / "+convert.str()+" GeV";
  hTT->SetTitle(temp.c_str());
  hTT->Scale(LumiScale);
  hTT->Rebin(binWidth);
  hTT->SetFillColor(39);
  gStyle->SetOptStat(0);

  //if(btag==0)
  //  hTT->GetYaxis()->SetRangeUser(0.0001,245);
  //if(btag==1)
  //  hTT->GetYaxis()->SetRangeUser(0.0001,245);
  //if(btag==2)
  //  hTT->GetYaxis()->SetRangeUser(0.0001,25);

  //hTT->Draw();


  TH1F *hVV =(TH1F*)VVFile->Get(histoName[btag].c_str());
  hVV->SetName("hVV");
  hVV->Scale(LumiScale);
  hVV->Rebin(binWidth);
  hVV->SetFillColor(38);

  TH1F* hH400 = (TH1F*)H400File->Get(histoName[btag].c_str());
  hH400->SetName("hH400");
  hH400->Scale(LumiScale*timesX);
  cout << "SIGNAL NORMALIZATION: " << hH400->Integral() << endl;
  hH400->Rebin(binWidth);
  hH400->SetFillColor(kYellow);//kRed+3);

  temp = ";m_{ZZ} [GeV];Events / "+convert.str()+" GeV";
  THStack *hBkg = new THStack("hBkg",temp.c_str());
  convert.str("");

  hBkg->Add(hVV);
  hBkg->Add(hTT);
  hBkg->Add(hZjets);
  hBkg->Add(hH400);

  float xMin = 150.;
  float xMax = 750.;
  float yMin = 0.;
  float yMax = 1.3*hBkg->GetMaximum();

  char yAxisName[500];
  sprintf( yAxisName, "Events / %.0f GeV", hVV->GetXaxis()->GetBinWidth(1) );
  //std::string yAxisName = "Events / "+convert.str()+" GeV";
  convert.str("");

//char xAxisName[400];
//sprintf( xAxisName, "m_{%s%sjj} [GeV]", leptType_forLegend.c_str(), leptType_forLegend.c_str() );

  TH2D* h2_axes = new TH2D("axes", "", 10, xMin, xMax, 10, yMin, yMax);
  h2_axes->SetXTitle("m_{lljj} [GeV]");
  h2_axes->SetYTitle(yAxisName);
  h2_axes->Draw();

  hBkg->Draw("SAMEHIST");
  plot_MCbkg->Draw("SAME");
  cmslabel->Draw();
  label_sqrt->Draw();
  // ---------------legend ---------------------------

  TLegend *leg = new TLegend(.4,.5,.8,.9);
  leg->SetTextSize(0.036);
  leg->SetFillColor(0);
  leg->SetBorderSize(0);
  convert.str("");
  convert << LumiScale/1000;
  temp="CMS Preliminary #sqrt{s}=7 TeV "+convert.str()+" fb^{-1}";
  //leg->SetHeader(temp.c_str());
  leg->AddEntry("background_Norm[mZZ]","Sideband Extrapolated Fit","l");
  //leg->AddEntry("model_Norm[mZZ]","Background+10#timesSignal","l");

  if(btag==0)
    temp="0 b-tag 2l2q data";
  if(btag==1)
    temp="1 b-tag 2l2q data";
  if(btag==2)
    temp="2 b-tag 2l2q data";

  leg->AddEntry("h_data_bkg",temp.c_str(),"p");
  leg->AddEntry("hZjets","Z + Jets","f");
  leg->AddEntry("hTT","tt/tW","f");
  leg->AddEntry("hVV","ZZ/WZ/WW","f");
  convert.str("");
  convert << timesX;
  temp="400 GeV SM Higgs#times"+convert.str();
  leg->AddEntry("hH400",temp.c_str(),"f");
  leg->Draw();

  string saveFileName="AllInOne_"+dataset + "_"+btagName[btag]+"tag_ll_LIMIT" + useNewShapeText + ".eps";

  c2->SaveAs(saveFileName.c_str()); 

}
Example #20
0
void vs_PlotQCDcomp() {

  Bool_t saveC  = false;
  Bool_t diJets = true;
  Bool_t isMC   = false;

  TString vsSave;
  vsSave = "_T07w";

  TString jSave;
  if(diJets) jSave = "2j";
  else       jSave = "3j";

  TString sample;
  if(diJets) sample = "select_1ph_2jets";
  else       sample = "select_1ph_3jets";

  TString FOtag;
  if(isMC) FOtag = "_FO_CorrMC";
  //  else     FOtag = "_FO_Corr";
  else     FOtag = "_FO";

  TString sysu = "SYSTUP_";
  TString sysd = "SYSTDOWN_";

  TString outDir;
  outDir = "Plots_PhotonSusyAnalysis/QCDweights/";


  //  string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/Merged_QCD_PhotonJet_T07w_PAT/mergedHistos.root";
  //  string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/Merged_Data_V05w_PAT/mergedHistos.root";
  string inputFile1 = "/data/user/vsola/CMSSW_Releases/CMSSW_5_3_9/src/Plots_PhotonSusyAnalysis/PhotonHadReReco_22Jan2013_V05_PAT/mergedHistos.root";
  
  
  setMyTDRStyle();
  gROOT->SetStyle("mytdrStyle");
  
  //  gStyle->SetHistMinimumZero();
  //  gStyle->SetPaintTextFormat("4.2f");

  gStyle->SetHistLineWidth(2);
  gStyle->UseCurrentStyle();

  //  gStyle->SetPadTopMargin(1.0);
  //  gStyle->SetPadLeftMargin(3.2);
  //  gStyle->SetPadRightMargin(4.5);
  //  gStyle->SetPadBottomMargin(3.2);

  gROOT->ForceStyle(1);


  static const Int_t nHt  =  7;
  static const Int_t nPt  = 13;
  static const Int_t nMet = 16;
  static const Int_t nJet = 15;

  Double_t binPt[nPt+1]   = {0.,75.,90.,120.,160.,210.,260.,320.,400.,500.,650.,800.,1000.,1500.};
  Double_t binHt[nHt+1]   = {0.,400.,450.,550.,700.,900.,1200.,1500.};
  Double_t binMet[nMet+1] = {0.,10.,20.,30.,40.,50.,60.,70.,80.,90.,100.,120.,160.,200.,270.,350.,500.};
  Double_t binJet[nJet+1] = {0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15};


  TLatex *as = new TLatex();
  as->SetNDC(true);
  as->SetTextColor(12);
  as->SetTextFont(43);
  as->SetTextSize(19);

  TLegend *legend = new TLegend(0.60, 0.70, 0.75, 0.85, "");
  legend->SetFillColor(10);
  legend->SetFillStyle(1001);
  legend->SetTextSize(0.04);
  legend->SetBorderSize(0);
  legend->SetShadowColor(0);

  std::string outLumi  = "CMS Work in Progress - QCD MC #sqrt{s} = 8 TeV - #geq 1 #gamma, #geq 2 j";

  TFile* f1 = TFile::Open( inputFile1.c_str() );

  //photon Pt
  TCanvas * cPt = new TCanvas("cPt","cPt");

  TH1F* hpt   = (TH1F*) f1->Get( sample+"/PreselCut_photonPt" );
  TH1F* hptFO = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_photonPt" );

  TH1F *hptR = (TH1F*) hpt->Rebin(nPt,hpt->GetTitle(),binPt);
  if (hptR->GetSumw2N() == 0)
    hptR->Sumw2();

  TH1F *hptFOR = (TH1F*) hptFO->Rebin(nPt,hptFO->GetTitle(),binPt);
  if (hptFOR->GetSumw2N() == 0)
    hptFOR->Sumw2();

  TH1F* hptSU = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_"+sysu+"photonPt" );
  TH1F* hptSD = (TH1F*) f1->Get( sample+FOtag+"/PreselCut_"+sysd+"photonPt" );

  TH1F *hptSUR = (TH1F*) hptSU->Rebin(nPt,hptSU->GetTitle(),binPt);
  if (hptSUR->GetSumw2N() == 0)
    hptSUR->Sumw2();

  TH1F *hptSDR = (TH1F*) hptSD->Rebin(nPt,hptSD->GetTitle(),binPt);
  if (hptSDR->GetSumw2N() == 0)
    hptSDR->Sumw2();

  if ( hptFOR != 0 ) {
    for (int b = 0; b < hptFOR->GetNbinsX(); b++) {

      Double_t mainHistoContent   = hptFOR->GetBinContent(b);
      Double_t systUpHistoContent = hptSUR->GetBinContent(b);
      Double_t systDnHistoContent = hptSDR->GetBinContent(b);
      Double_t systDiffUp = fabs( (double) systUpHistoContent - mainHistoContent );
      Double_t systDiffDn = fabs( (double) mainHistoContent - systDnHistoContent );

      // use average error for histogram
      Double_t systDiff = ( systDiffUp + systDiffDn ) / 2.;
      
      Double_t statErr   = hptFOR->GetBinError(b);
      Double_t combError = sqrt( systDiff * systDiff + statErr * statErr );
      hptFOR->SetBinError(b, combError);
    } //for
  }//if
    
  cPt->SetLogy(1);
  gPad->Update();
  cPt->Update();

  //  hptR->Scale(1,"width");
  //  hptR->SetMinimum(0.02);
  //  hptR->SetMaximum(1000); 
  hptR->GetXaxis()->SetTitle("1^{st} photon p_{T} [GeV]");
  hptR->GetYaxis()->SetTitle("Number of Events / GeV");

  if(isMC) hptR->SetMarkerSize(0);
  if(isMC) hptR->Draw("histE");
  else     hptR->Draw("E X0");


  hptFOR->SetMarkerSize(0);
  hptFOR->SetLineColor(2);
  hptFOR->SetFillColor(2);
  hptFOR->SetFillStyle(3004);
  hptFOR->Draw("same hist ][ E2");

  legend->Clear();
  if(isMC) legend->SetHeader("#gamma/QCD (Sim)");
  else     legend->SetHeader("#gamma/QCD (Data)");
  if(isMC) legend->AddEntry(hptR, "#gamma", "l");
  else     legend->AddEntry(hptR, "#gamma", "p");
  legend->AddEntry(hptFOR, "Pred (from #gamma_{jet})", "f");
  legend->Draw();

  as->DrawLatex(0.17, 0.93, outLumi.c_str() );
  cPt->Update();
  cPt->SetBottomMargin(0.2 + 0.8 * cPt->GetBottomMargin() - 0.2 * cPt->GetTopMargin());

  TPad *ratioPt = new TPad("BottomPad", "", 0, 0, 1, 1);
  ratioPt->SetTopMargin(0.8 - 0.8 * ratioPt->GetBottomMargin() + 0.2 * ratioPt->GetTopMargin());
  ratioPt->SetFillStyle(0);
  ratioPt->SetFrameFillColor(10);
  ratioPt->SetFrameBorderMode(0);
  ratioPt->Draw();

  ratioPt->cd();
  ratioPt->SetLogy(0);

  TH1F *hptRat = (TH1F*) divideHistosForRatio(hptR,hptFOR);
  hptRat->SetMinimum(0.);
  hptRat->SetMaximum(10.);
  hptRat->GetXaxis()->SetNdivisions(505);
  if(isMC) hptRat->GetYaxis()->SetTitle("Sim/Pred");
  else     hptRat->GetYaxis()->SetTitle("Data/Pred");
  hptRat->GetYaxis()->SetTitleSize(0.04);
  hptRat->GetYaxis()->SetLabelSize(0.03);
  hptRat->GetYaxis()->SetTitleOffset(1.3);
  hptRat->GetYaxis()->SetNdivisions(505);
  hptRat->SetMarkerStyle(20);
  hptRat->SetMarkerSize(1);
  hptRat->SetMarkerColor(1);
  hptRat->SetLineColor(1);
  hptRat->Draw("E X0");

  TH1F *hptFRat = (TH1F*) getSystErrForRatio(hptFOR);
  hptFRat->SetLineColor(2);
  hptFRat->SetFillColor(2);
  hptFRat->SetFillStyle(3004);
  hptFRat->Draw("same hist ][ E2");


  TLine * line = new TLine( hptRat->GetXaxis()->GetXmin(), 1., hptRat->GetXaxis()->GetXmax(), 1. );
  line->SetLineColor(1);
  line->SetLineWidth(0.5);
  line->SetLineStyle(1);
  line->Draw("same");

  hptR->GetXaxis()->SetLabelSize(0);
  hptR->GetXaxis()->SetTitle("");
  cPt->RedrawAxis();
  gPad->Update();
  cPt->Update();


  return;
}
Example #21
0
int main(int argc, char *argv[]) {

  // make sure command line arguments were supplied
  if (argc != 6) { cerr << "Usage: " << argv[0] << " [reference.root] [new-comparison.root] [root dir] [new-release] [old-release] \n"; return 1; }

  // create the comparison class
  PlotCompareUtility *pc = new PlotCompareUtility(argv[1],argv[2],argv[3],"METTask_");
  HistoData *hd;

  if (pc->GetStatus() != 0) { cout << "Final Result: no_data" << endl; return 0; }

  // add histogram information
  //Type = 0 (Do not rebin or zoom) , 1 (Rebin and Zoom, x-axis > 0 ) , 2 (Rebin and Zoom)
  hd = pc->AddHistoData("MET"); hd->SetType(1);
  hd = pc->AddHistoData("METPhi"); hd->SetType(2);
  hd = pc->AddHistoData("METSig"); hd->SetType(1);
  hd = pc->AddHistoData("MEx"); hd->SetType(2);
  hd = pc->AddHistoData("MEy"); hd->SetType(2);
  hd = pc->AddHistoData("SumET"); hd->SetType(2);

  if (pc->GetStatus() != 0) { cerr << "error encountered, exiting.\n"; return pc->GetStatus(); }

  int num_histos = pc->GetNumHistos();
  bool combinedFailed = false;
  float threshold = KS_TEST ?  pc->GetKSThreshold() : pc->GetChi2Threshold(); 

    // get the reference and comparison histograms
  int Nevents_ref = ((TH1F *)pc->GetRefHisto("Nevents"))->GetEntries();
  int Nevents_new = ((TH1F *)pc->GetNewHisto("Nevents"))->GetEntries();
  int Nevents = -1;
  if (Nevents_ref>Nevents_new) Nevents = Nevents_ref;
  else Nevents = Nevents_new;

  // create summary histograms
  TH1F h1dResults_passed("h1dResults_passed","",num_histos, 1, num_histos + 1);
  TH1F h1dResults_failed("h1dResults_failed","",num_histos, 1, num_histos + 1);

  // loop over the supplied list of histograms for comparison
  for (int index = 0; index < pc->GetNumHistos(); index++) {

    int number = index + 1;
    hd = pc->GetHistoData(number);
    //int type = hd->GetType();
    //types[index] = type;
    string name = hd->GetName();
    //string value = hd->GetValueX();
    cout << name << endl;

    // get the reference and comparison histograms
    TH1F *href = (TH1F *)pc->GetRefHisto(name);
    TH1F *hnew = (TH1F *)pc->GetNewHisto(name);


    // ignore if histogram is empty
    if (hnew->GetEntries() <= 1 || href->GetEntries() <= 1) {
      cerr << name << " error: no entries"; combinedFailed = true; continue;
    }

    // calculate and set range and number of bins
    double h1RMS =  hnew->GetRMS();
    double h2RMS =  href->GetRMS();
    double RMS = TMath::Max(h1RMS, h2RMS);
    double h1Mean =  hnew->GetMean();
    double h2Mean =  href->GetMean();
    double Mean = 0.5 * (h1Mean + h2Mean);
    double Nbins = href->GetNbinsX();
    double min = href->GetXaxis()->GetXmin();
    double max = href->GetXaxis()->GetXmax();
    double dX = max - min;
    double dNdX = 1;
    double NewMin = min;
    double NewMax = max;

    int rebinning = Nbins; 

    if (RMS>0 && hd->GetType() ) 
      {
	dNdX = 100. / ( 10 * RMS);
	NewMin = Mean - 10 * RMS;
	NewMax = Mean + 10 * RMS;
      }
    
    if ((dX * dNdX)>0  && hd->GetType() ) 
      rebinning = (int)(double(Nbins) / (dX * dNdX));
    
    if ( rebinning > 1 && hd->GetType() ) 
      {
	href->Rebin(rebinning);
	hnew->Rebin(rebinning);
      }

    if ( hd->GetType() == 1 )
      { 
	href->GetXaxis()->SetRangeUser(0.0, NewMax);
	hnew->GetXaxis()->SetRangeUser(0.0, NewMax);
      }
    else if ( hd->GetType() == 2 )
      {
	href->GetXaxis()->SetRangeUser(NewMin, NewMax);
	hnew->GetXaxis()->SetRangeUser(NewMin, NewMax);
      }

    // perform statistical tests
    double ks_score = hnew->KolmogorovTest(href,"D");
    double chi2_score = hnew->Chi2Test(href, "p");
    //double result = KS_TEST ? ks_score : chi2_score;
    double result = (ks_score>chi2_score) ? ks_score : chi2_score;
    
      href->SetNormFactor(Nevents_new);     	
      hnew->SetNormFactor(Nevents_new);
    //hnew->SetNormFactor(1);

    // ensure that the peaks of both histograms will be shown by making a dummy histogram
    float Nentries_ref = href->GetEntries();
    float Nentries_new = hnew->GetEntries();
    float XaxisMin_ref = 0, XaxisMax_ref = 0, YaxisMin_ref = 0, YaxisMax_ref = 0;
    float XaxisMin_new = 0, XaxisMax_new = 0, YaxisMin_new = 0, YaxisMax_new = 0;
    if (Nentries_ref>0) YaxisMax_ref = (href->GetMaximum()+TMath::Sqrt(href->GetMaximum()))*(Nentries_new/Nentries_ref);
    if (Nentries_new>0) YaxisMax_new = (hnew->GetMaximum()+TMath::Sqrt(hnew->GetMaximum()));

    XaxisMin_ref = href->GetXaxis()->GetXmin()>NewMin  ? href->GetXaxis()->GetXmin() : NewMin;
    XaxisMax_ref = href->GetXaxis()->GetXmax()<=NewMax ? href->GetXaxis()->GetXmax() : NewMax;
    YaxisMax_ref = (YaxisMax_ref>=YaxisMax_new) ? YaxisMax_ref : YaxisMax_new;

    if (TMath::Abs(XaxisMin_ref - XaxisMax_ref)<1E-6)
      {
	XaxisMin_ref = 0;
	XaxisMax_ref = 1;
      }
    
    TH1F *hdumb = new TH1F("hdumb","", rebinning, XaxisMin_ref, XaxisMax_ref);
    hdumb->SetMinimum(1E-1); //--For Rick
    hdumb->SetMaximum(1.05*YaxisMax_ref);
    //    if (href->GetMaximum() < hnew->GetMaximum())
    //  href->SetAxisRange(0, 1.1 * hnew->GetMaximum(), "Y");
        
    // set drawing options on the reference histogram
    href->SetStats(0);
    href->SetLineWidth(2);
    href->SetLineColor(14);
    href->SetMarkerColor(14);
    href->SetFillColor(17);
    //href->SetFillStyle(3004);
    href->GetXaxis()->SetTitle(name.c_str());
    href->GetYaxis()->SetTitle("Entries");
    href->GetYaxis()->SetTitleOffset(1.5);

    // set drawing options on the new histogram
    hnew->SetStats(0);
    hnew->SetLineWidth(2);
    hnew->SetFillStyle(3001);
    // set drawing options on the dummy histogram
    hdumb->SetStats(0);
    hdumb->GetXaxis()->SetTitle(name.c_str());
    hdumb->GetXaxis()->SetLabelSize(0.5 * hdumb->GetXaxis()->GetTitleSize());
    hdumb->GetYaxis()->SetTitle("Entries");
    hdumb->GetYaxis()->SetTitleOffset(1.5);
    hdumb->GetYaxis()->SetLabelSize(0.5 * hdumb->GetXaxis()->GetTitleSize());
    
    stringstream ss_title;
    ss_title.precision(5);
    if (ks_score>chi2_score)
      ss_title << "KS Score = " << ks_score;
    else
      ss_title << "Chi^2 Score = " << chi2_score;
    TText canvas_title(0.1,0.97,ss_title.str().c_str());


    // determine if test is a "pass" or a "fail"
    if (result <= threshold) {

      canvas_title.SetTextColor(kRed);

      // make this histogram red to denote failure
      hnew->SetFillColor(kRed);
      hnew->SetLineColor(206);
      hnew->SetMarkerColor(206);

      // mark the entire sample as being 'not-compatible'
      combinedFailed = true;

      // set the summary bin to failed (only need to set titles for passed h1dResults)
      h1dResults_passed.GetXaxis()->SetBinLabel(number, name.c_str());
      h1dResults_failed.SetBinContent(number, result);

    } else {

      canvas_title.SetTextColor(kGreen);

      // make this histogram green to denote passing score
      hnew->SetFillColor(kGreen);
      hnew->SetLineColor(103);  
      hnew->SetMarkerColor(103);

      // set the summary bin to passed
      h1dResults_passed.GetXaxis()->SetBinLabel(number, name.c_str());
      h1dResults_passed.SetBinContent(number, result);

    }

    // setup canvas for displaying the compared histograms
    TCanvas histo_c("histo_c","histo_c",785,800);
    histo_c.Draw();

    TPad histo_p("histo_p","histo_p",0,0,1,0.99);
    histo_p.Draw();

    histo_c.cd();
    canvas_title.SetTextSize(0.025);
    canvas_title.Draw();

    histo_p.cd();

    histo_p.SetLogy(1); //--This is just for Dr. Rick
    hdumb->Draw();
    href->Draw("SAME");
    hnew->Draw("SAME");
    hnew->Draw("E1SAME");

      stringstream legend_new;
      stringstream legend_ref;
      legend_new << argv[4] << ": " << Nentries_new << " entries, " << Nevents_new << " events";
      legend_ref << argv[5] << ": " << Nentries_ref << " entries, " << Nevents_ref << " events";		
	
      TLegend l1(0.15,0.001,0.33, 0.06);
      l1.SetTextSize(0.02);
      l1.AddEntry(hnew, legend_new.str().c_str(),"lF");
      l1.AddEntry(href, legend_ref.str().c_str(),"lF");
      l1.SetFillColor(kNone);      
      l1.Draw("SAME");


    // print the result to gif
    string histo_name = name + ".gif";
    histo_c.Print(histo_name.c_str(),"gif");
    cout << "Result of comparison for " << name << ": ks score = " << ks_score << " : chi2 score = " << chi2_score << endl << endl;

  }

  // create summary canvas
  int summary_height = int(780 * float(num_histos) / 11); // 780;
  TCanvas main_c("main_c","main_c",799,summary_height);
  main_c.Draw();

  TPad main_p("main_p","main_p",0.01,0.01,0.99,0.94);
  main_p.SetLeftMargin(0.30);
  main_p.SetBottomMargin(0.15);
  main_p.SetLogx(1);
  main_p.SetGrid();
  main_p.SetFrameFillColor(10);
  main_p.Draw();

  main_c.cd();
  TText summary_title(.01, .95, "");
  summary_title.Draw("SAME");

  main_p.cd();

  // setup the passing test bars
  h1dResults_passed.SetStats(0);
  h1dResults_passed.GetXaxis()->SetLabelSize(0.06);
  h1dResults_passed.GetYaxis()->SetLabelSize(0.04);
  h1dResults_passed.GetYaxis()->SetTitle("Compatibility");
  h1dResults_passed.SetBarWidth(0.7);
  h1dResults_passed.SetBarOffset(0.1);
  h1dResults_passed.SetFillColor(kGreen);
  h1dResults_passed.SetLineColor(1);
  h1dResults_passed.GetYaxis()->SetRangeUser(1E-7,2);
  h1dResults_passed.Draw("hbar0");

  // setup the failing test bars
  h1dResults_failed.SetStats(0);
  h1dResults_failed.GetXaxis()->SetLabelSize(0.06);
  h1dResults_failed.GetYaxis()->SetLabelSize(0.04);
  h1dResults_failed.GetYaxis()->SetTitle("Compatibility");
  h1dResults_failed.SetBarWidth(0.7);
  h1dResults_failed.SetBarOffset(0.1);
  h1dResults_failed.SetFillColor(kRed);
  h1dResults_failed.SetLineColor(1);
  h1dResults_failed.GetYaxis()->SetRangeUser(1E-7,2);
  h1dResults_failed.Draw("hbar0SAME");

  // draw the pass/fail threshold line
  TLine l(threshold, 1, threshold, num_histos+1);
  l.SetLineColor(kRed);
  l.SetLineWidth(2);
  l.SetLineStyle(2);
  l.Draw("SAME"); 

  // print the results
  main_c.Update();
  main_c.Print("AllResults-1dHistoCheck.gif","gif");

  if (combinedFailed) cout << "Final Result: fail" << endl;
  else cout << "Final Result: pass" << endl;

  //delete pc;
  return 0;

}
Example #22
0
void controlPlots(){
  gStyle->SetOptStat(0);

  std::vector<bool> *bvec = new std::vector<bool>; 

  bvec->push_back(0); 

  std::cout << bvec->size() << std::endl;

//   string dir="/shome/wehrlilu/SecVtx/SVProd/SVVALIDATION/forbatchjobs/temp/BBC/CMSSW_3_7_0_patch2/src/crab/analyze/rootoutput/tempPTplots2/"; 
  string dir="/shome/wehrlilu/SecVtx/SVProd/SVVALIDATION/forbatchjobs/temp/BBC/CMSSW_3_7_0_patch2/crab/analyze/rootoutput/tempPTplotsALL/"; 
  string dirMC="mc/"; 
  string dirDATA="data/";
  string strigger="jet30/";

  //LUMI DATA FOR JET30: 0.313154 JET50U: 3.06903 ((IN /PB))
  //MC LUMI IS 1/PB
  bool luminorm=0; double lumiDATA=0.313154;
  bool log=0; 

//   bool twoBonly = true; 

//   //pt hard reco (2V events)
//   string histoname = "Vert_ptrechard_2bVert"; 
//   string axis = "harder vertex pt"; 
//   int nbins = 100; double lower=0.0, upper = 200;
//   unsigned int rebinBy=2; 

  //pt soft reco (2V events)
  string histoname = "Vert_ptrecsoft_2bVert"; 
  string axis = "softer vertex pt"; 
  int nbins = 100; double lower=0.0, upper = 200;
  unsigned int rebinBy=2; 

//   //average pt reco (2V events)
//   string histoname = "Vert_ptrecaver_2bVert"; 
//   string axis = "average vertex pt"; 
//   int nbins = 100; double lower=0.0, upper = 200;
//   unsigned int rebinBy=2; 

//   //asymmetry pt reco (2V events)
//   string histoname = "Vert_ptrecasym_2bVert"; 
//   string axis = "asymmetry of vertex pt"; 
//   int nbins = 50; double lower=0.0, upper = 1.0;
//   unsigned int rebinBy=2; 


//   if(twoBonly) histoname = histoname + "_2b";


  TFile *fMC1 = TFile::Open((dir+dirMC+"histos_qcdpt15_test_v2.root").c_str()); 
  TFile *fMC2 = TFile::Open((dir+dirMC+"histos_qcdpt30_test_v2_125of127.root").c_str()); 
  TFile *fMC3 = TFile::Open((dir+dirMC+"histos_qcdpt80_test_v3.root").c_str()); 
  TFile *fMC4 = TFile::Open((dir+dirMC+"histos_qcdpt170_test_v1_79of80.root").c_str()); 

  TFile *fDATA = TFile::Open((dir+dirDATA+"histo_allDATAupTo144114.root").c_str()); 
  

  TH1F *hMC1; fMC1->GetObject((strigger+histoname).c_str(),hMC1);
  TH1F *hMC2; fMC2->GetObject((strigger+histoname).c_str(),hMC2);
  TH1F *hMC3; fMC3->GetObject((strigger+histoname).c_str(),hMC3); 
  TH1F *hMC4; fMC4->GetObject((strigger+histoname).c_str(),hMC4);

  TH1F *hMCcombined= new TH1F("hMCcombined",axis.c_str(),nbins,lower,upper);
  TH1F *hDATA; fDATA->GetObject((strigger+histoname).c_str(),hDATA);

  TCanvas *c = new TCanvas("quant",axis.c_str(),100,300,500,500);



  hMC1->SetFillColor(0);
  hMC2->SetFillColor(0);
  hMC3->SetFillColor(0);
  hMC4->SetFillColor(0);
  hMCcombined->SetFillColor(0);
  hDATA->SetFillColor(0);

  hMC1->Scale(143.866);
  hMC2->Scale(12.1072);
  hMC3->Scale(0.310862);
  hMC4->Scale(0.0082391);

  hMCcombined->Add(hMC1);
  hMCcombined->Add(hMC2);
  hMCcombined->Add(hMC3);
  hMCcombined->Add(hMC4);


  //norm  
  if(luminorm){
    hMCcombined->Scale(lumiDATA); 
  }
  else{
    double intMC=hMCcombined->Integral(); 
    double intDATA=hDATA->Integral(); 
    hMCcombined->Scale(intDATA/intMC); 
  }

  //numbers, cuts
  std::cout << "data lumi (/pb): " << lumiDATA << std::endl;
  std::cout << "trigger used: " << strigger << std::endl;
  std::cout << "Numbers\n";
  std::cout << "MC:\t" << hMCcombined->Integral() << std::endl;
  std::cout << "DATA:\t" << hDATA->Integral() << std::endl;

  //rebin
  hMCcombined->Rebin(rebinBy);
  hDATA->Rebin(rebinBy);

  //format
  if(log) c->SetLogy();
  double dmax = hMCcombined->GetMaximum(); 
  if(dmax<hDATA->GetMaximum()) dmax = hDATA->GetMaximum(); 
  if(log)  hMCcombined->GetYaxis()->SetRangeUser(0.01,dmax*10.0); 
  else hMCcombined->GetYaxis()->SetRangeUser(0.01,dmax+dmax/10.0); 
  
  hMCcombined->GetXaxis()->SetTitle(axis.c_str()); 
  hMCcombined->SetFillColor(8); 
  hMCcombined->SetLineColor(8); 
  hDATA->SetMarkerStyle(21); 
  
  //draw
  hMCcombined->Draw("hist");
  hDATA->Draw("samesPE");

  //leg
  TLegend *leg = new TLegend(0.65,0.75,0.9,0.9); 
  leg->SetFillColor(0); 
  leg->AddEntry(hDATA,"Data","PE"); 
  leg->AddEntry(hMCcombined,"Pythia","F");
  leg->Draw(); 


}
Example #23
0
void RAA_plot_JetID_CutEfficiency(  Int_t radius = 4,
				    char * etaWidth = (char*)"20_eta_p20"){

  TH1::SetDefaultSumw2();
  gStyle->SetOptStat(0);

  char * Coll = "PbPb";
  //char * Coll = "Pp";

  TDatime date;

  Int_t trigger[3]; 

  if(Coll == "PbPb") {trigger[0] = 55; trigger[1] = 65; trigger[2] = 80;}
  if(Coll == "Pp") {trigger[0] = 40; trigger[1] = 60; trigger[2] =  80;}

  char * jetType; 

  if(Coll == "PbPb") jetType = Form("akPu%dPF",radius);
  if(Coll == "Pp") jetType = Form("ak%dPF",radius);

  const int nbins_pt = 38;
  const double boundaries_pt[nbins_pt+1] = {
    3, 4, 5, 7, 9, 12, 
    15, 18, 21, 24, 28,
    32, 37, 43, 49, 56,
    64, 74, 84, 97, 114,
    133, 153, 174, 196,
    220, 245, 300, 
    330, 362, 395, 430,
    468, 507, 548, 592,
    638, 686, 1000 
  };
  
  // Pawan's files:
  TFile * fIn = TFile::Open(Form("/export/d00/scratch/rkunnawa/rootfiles/RAA/Pawan_ntuple_PbPb_data_MC_subid0_spectra_JetID_CutA_finebins_%s_R0p%d.root",etaWidth,radius));
  TFile * fPP_in = TFile::Open(Form("/export/d00/scratch/rkunnawa/rootfiles/RAA/Pawan_ntuple_PP_data_MC_spectra_residualFactor_finebins_%s_R0p%d.root",etaWidth, radius));
  
  // get the histograms, the Cut Efficiency is plotted from the MC histograms 
  TH1F * hMC_noCut[3], * hMC_Cut[3], * hMC_unm_noCut[3], * hMC_unm_Cut[3]; 

  TH1F * hMC_Denominator, *hMC_Numerator;

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

    hMC_noCut[i] = (TH1F*)fIn->Get(Form("hMC_Jet%d_noCut", trigger[i]));
    hMC_Cut[i] = (TH1F*)fIn->Get(Form("hMC_Jet%d_CutA", trigger[i]));
    hMC_unm_noCut[i] = (TH1F*)fIn->Get(Form("hMC_unmatched_Jet%d_noCut", trigger[i]));
    hMC_unm_Cut[i] = (TH1F*)fIn->Get(Form("hMC_unmatched_Jet%d_CutA", trigger[i]));

  }

  hMC_Denominator = (TH1F*)hMC_noCut[0]->Clone("hMC_Denominator");
  hMC_Denominator->Add(hMC_noCut[1]);
  hMC_Denominator->Add(hMC_noCut[2]);
  hMC_Denominator->Add(hMC_unm_noCut[0]);
  hMC_Denominator->Add(hMC_unm_noCut[1]);
  hMC_Denominator->Add(hMC_unm_noCut[2]);
  
  hMC_Numerator = (TH1F*)hMC_Cut[0]->Clone("hMC_Numerator");
  hMC_Numerator->Add(hMC_Cut[1]);
  hMC_Numerator->Add(hMC_Cut[2]);
  hMC_Numerator->Add(hMC_unm_Cut[0]);
  hMC_Numerator->Add(hMC_unm_Cut[1]);
  hMC_Numerator->Add(hMC_unm_Cut[2]);

  TH1F * hCutEff = (TH1F*)hMC_Numerator->Clone("hCutEff");
  hCutEff->Divide(hMC_Denominator);
  hCutEff = (TH1F*)hCutEff->Rebin(nbins_pt, "hCutEff", boundaries_pt);
  divideBinWidth(hCutEff);

  // line at 1

  
  TCanvas * cCutEff = new TCanvas("cCutEff","",800,600);
  hCutEff->SetXTitle(Form("%s Gen p_{T} (GeV/c)",jetType));
  hCutEff->SetYTitle("Jet ID Cut Efficiency");
  hCutEff->SetTitle(" ");
  hCutEff->SetAxisRange(40, 300, "X");
  hCutEff->SetAxisRange(0.9, 1.05, "Y");
  hCutEff->SetMarkerStyle(20);
  hCutEff->SetMarkerColor(kBlack);
  hCutEff->Draw();

  putCMSPrel();
  drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20);
  drawText(Form("%s",Coll), 0.6, 0.21, 20);

  cCutEff->SaveAs(Form("May20/%s_Combined_CutEfficiency_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE");
  


  // plot the curves for the different centrality classes. get the combined spectra and do the ratio 
  
  const int nbins_cent = 6; 

  TH1F * hMC_Denominator[nbins_cent];
  TH1F * hMC_Numerator[nbins_cent]; 

  TH1F * hData_Denominator[nbins_cent];
  TH1F * hData_Numerator[nbins_cent]; 

  TH1F * hCutEff[nbins_cent];
  TH1F * hCutEff_Data[nbins_cent];

  TH1F * hPP_MC_Denominator = (TH1F*)fIn_PP->Get("hpp_MC_Comb_noCut");
  TH1F * hPP_MC_Numerator = (TH1F*)fIn_PP->Get(Form("hpp_JetComb_gen_R%d_%s",radius,etaWidth)); 

  TH1F * hPP_Data_Denominator = (TH1F*)fIn_PP->Get("hpp_Data_Comb_noCut");
  TH1F * hPP_Data_Numerator = (TH1F*)fIn_PP->Get(Form("hpp_HLTComb_R%d_%s",radius,etaWidth)); 

  TH1F * hPP_CutEff = (TH1F*)hPP_MC_Numerator->Clone("hPP_CutEff");
  hPP_CutEff->Divide(hPP_MC_Denominator);
  hPP_CutEff->Rebin(10);
  hPP_CutEff->Scale(1./10);
  TH1F * hPP_CutEff_Data = (TH1F*)hPP_Data_Numerator->Clone("hPP_CutEff_Data");
  hPP_CutEff_Data->Divide(hPP_Data_Denominator);
  hPP_CutEff_Data->Rebin(10);
  hPP_CutEff_Data->Scale(1./10);
  
  TLine *line = new TLine(60,1,299,1);
  line->SetLineStyle(2);
  line->SetLineWidth(2);

  for(int i = 0; i<nbins_cent; ++i){
    
    hMC_Denominator[i] = (TH1F*)fIn->Get(Form("hpbpb_MC_noCut_cent%d",i));
    hMC_Numerator[i] = (TH1F*)fIn->Get(Form("hpbpb_gen_R%d_%s_cent%d",radius,etaWidth, i));
    hData_Denominator[i] = (TH1F*)fIn->Get(Form("hpbpb_Data_Comb_noCut_cent%d",i));
    hData_Numerator[i] = (TH1F*)fIn->Get(Form("hpbpb_HLTComb_R%d_%s_cent%d",radius,etaWidth,i));

    hCutEff[i] = (TH1F*)hMC_Numerator[i]->Clone(Form("CutEff_cent%d",i));
    hCutEff[i]->Divide(hMC_Denominator[i]);
    hCutEff[i]->Rebin(20);
    hCutEff[i]->Scale(1./20);

    hCutEff_Data[i] = (TH1F*)hData_Numerator[i]->Clone(Form("CutEff_Data_cent%d",i));
    hCutEff_Data[i]->Divide(hData_Denominator[i]);
    hCutEff_Data[i]->Rebin(20);
    hCutEff_Data[i]->Scale(1./20);

  }

  TCanvas * cCutEff = new TCanvas("cCutEff","",800,600);
  makeMultiPanelCanvas(cCutEff,3,2,0.0,0.0,0.2,0.15,0.07);

  for(int i = 0; i<nbins_cent; ++i){
    cCutEff->cd(nbins_cent-i);
    hCutEff[i]->SetXTitle(Form("akPu%dPF Gen p_{T} (GeV/c)", radius));
    hCutEff[i]->SetYTitle("Jet ID Cut Efficiency");
    hCutEff[i]->SetTitle(" ");
    hCutEff[i]->SetAxisRange(50, 299, "X");
    hCutEff[i]->SetAxisRange(0.95, 1.05, "Y");
    hCutEff[i]->SetMarkerStyle(20);
    hCutEff[i]->SetMarkerColor(kBlack);
    hCutEff[i]->Draw();
    line->Draw();
  }

  putCMSPrel();
  drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20);
  drawText(Form("%s",Coll), 0.6, 0.21, 20);

  cCutEff->SaveAs(Form("May20/%s_Combined_CutEfficiency_centralityClass_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE");

  TCanvas * cCutEff_Data = new TCanvas("cCutEff_Data","",800,600);
  makeMultiPanelCanvas(cCutEff_Data,3,2,0.0,0.0,0.2,0.15,0.07);

  for(int i = 0; i<nbins_cent; ++i){
    cCutEff_Data->cd(nbins_cent-i);
    hCutEff_Data[i]->SetXTitle(Form("akPu%dPF Data reco p_{T} (GeV/c)", radius));
    hCutEff_Data[i]->SetYTitle("Jet ID Cut Efficiency");
    hCutEff_Data[i]->SetTitle(" ");
    hCutEff_Data[i]->SetAxisRange(60, 299, "X");
    hCutEff_Data[i]->SetAxisRange(0.2, 1.1, "Y");
    hCutEff_Data[i]->SetMarkerStyle(20);
    hCutEff_Data[i]->SetMarkerColor(kBlack);
    hCutEff_Data[i]->Draw();
    line->Draw();
  }

  putCMSPrel();
  drawText("|#eta|<2, |vz|<15", 0.6, 0.31, 20);
  drawText(Form("%s",Coll), 0.6, 0.21, 20);

  cCutEff_Data->SaveAs(Form("May20/%s_Combined_CutEfficiency_Data_centralityClass_R0p%d_%s_%d.pdf",Coll,radius,etaWidth,date.GetDate()),"RECREATE");

  
  TCanvas * cPP_CutEff = new TCanvas("cPP_CutEff","",800,600);
  hPP_CutEff->SetXTitle(Form("ak%dPF Gen p_{T} (GeV/c)", radius));
  hPP_CutEff->SetYTitle("Jet ID Cut Efficiency");
  hPP_CutEff->SetTitle(" ");
  hPP_CutEff->SetAxisRange(60, 299, "X");
  hPP_CutEff->SetAxisRange(0.8,1.1,"Y");
  hPP_CutEff->SetMarkerStyle(20);
  hPP_CutEff->Draw();

  cPP_CutEff->SaveAs(Form("May20/PP_Combined_CutEfficiency_R0p%d_%d.pdf",radius, date.GetDate()));

  TCanvas * cPP_CutEff_Data = new TCanvas("cPP_CutEff_Data","",800,600);
  hPP_CutEff_Data->SetXTitle(Form(" ak%dPF Data reco p_{T} (GeV/c)", radius));
  hPP_CutEff_Data->SetYTitle("Jet ID Cut Efficiency");
  hPP_CutEff_Data->SetTitle(" ");
  hPP_CutEff_Data->SetAxisRange(60, 299, "X");
  hPP_CutEff_Data->SetAxisRange(0.8,1.1,"Y");
  hPP_CutEff_Data->SetMarkerStyle(20);
  hPP_CutEff_Data->Draw();

  cPP_CutEff_Data->SaveAs(Form("May20/PP_Combined_CutEfficiency_Data_R0p%d_%s_%d.pdf",radius,etaWidth, date.GetDate()));
  
}
Example #24
0
void PlotEff() {

    gROOT->ProcessLine(".L ./tdrstyle.C");
    setTDRStyle();

    TFile *f1 = TFile::Open("./histo_file_HToTauTau_13TeV_Fall13dr_PU20bx25.root");
    TFile *f2 = TFile::Open("./histo_file_HToTauTau_13TeV_Fall13dr_PU40bx25.root");
    TFile *f3 = TFile::Open("./histo_file_HToTauTau_8TeV_HighPt.root");

    gStyle->SetOptStat(0000000);
    TH1F* hTauGenMatchPt_AfterLooseIso3H = (TH1F*)f1->Get("hTauGenMatchPt_AfterLooseIso3H");
    hTauGenMatchPt_AfterLooseIso3H->Rebin(4);
    TH1F* hGenTauPt = (TH1F*)f1->Get("hTauGenMatchPt");
    hGenTauPt->Rebin(4);
    TH1F* EffLooseIso3Hits_Pt =new TH1F("EffLooseIso3Hits_Pt","EffLooseIso3Hits_Pt",50,0,200);
    EffLooseIso3Hits_Pt->Divide(hTauGenMatchPt_AfterLooseIso3H,hGenTauPt, 1. ,  1. , "B");

    TH1F* hTauGenMatchEta_AfterLooseIso3H = (TH1F*)f1->Get("hTauGenMatchEta_AfterLooseIso3H");
    hTauGenMatchEta_AfterLooseIso3H->Rebin(2);
    TH1F* hGenTauEta = (TH1F*)f1->Get("hTauGenMatchEta");
    hGenTauEta->Rebin(2);
    TH1F* EffLooseIso3Hits_Eta =new TH1F("EffLooseIso3Hits_Eta","EffLooseIso3Hits_Eta",50,-3,3);
    EffLooseIso3Hits_Eta->Divide(hTauGenMatchEta_AfterLooseIso3H,hGenTauEta, 1. ,  1. , "B");

    TH1F* hTauGenMatchPhi_AfterLooseIso3H = (TH1F*)f1->Get("hTauGenMatchPhi_AfterLooseIso3H");
    TH1F* hGenTauPhi = (TH1F*)f1->Get("hTauGenMatchPhi");
    TH1F* EffLooseIso3Hits_Phi =new TH1F("EffLooseIso3Hits_Phi","EffLooseIso3Hits_Phi",100,-3,3);
    EffLooseIso3Hits_Phi->Divide(hTauGenMatchPhi_AfterLooseIso3H,hGenTauPhi, 1. ,  1. , "B");

    TH1F* hOfflinePV_AfterLooseIso3H = (TH1F*)f1->Get("hOfflinePV_AfterLooseIso3H");
    TH1F* hOfflinePV = (TH1F*)f1->Get("hOfflinePV");
    f1->cd();
    TH1F* hOfflinePV = (TH1F*)hOfflinePV->Clone();
    //hOfflinePV_AfterLooseIso3H->SetRange(0,70);
    //hOfflinePV->SetRangeUser(0,70);

    TH1F* EffLooseIso3Hits_NPV =new TH1F("EffLooseIso3Hits_NPV","EffLooseIso3Hits_NPV",100,0,100);
    EffLooseIso3Hits_NPV->Divide(hOfflinePV_AfterLooseIso3H, hOfflinePV, 1. ,  1. , "B");



    //////////////////////////////////////////////////////////////////////////////////////////////
    TH1F* hTauGenMatchPt_AfterLooseIso3H_40 = (TH1F*)f2->Get("hTauGenMatchPt_AfterLooseIso3H");
    hTauGenMatchPt_AfterLooseIso3H_40->Rebin(4);
    TH1F* hGenTauPt_40 = (TH1F*)f2->Get("hTauGenMatchPt");
    hGenTauPt_40->Rebin(4);
    TH1F* EffLooseIso3Hits_Pt_40 =new TH1F("EffLooseIso3Hits_Pt_40","EffLooseIso3Hits_Pt_40",50,0,200);
    EffLooseIso3Hits_Pt_40->Divide(hTauGenMatchPt_AfterLooseIso3H_40,hGenTauPt_40, 1. ,  1. , "B");

    TH1F* hTauGenMatchEta_AfterLooseIso3H_40 = (TH1F*)f2->Get("hTauGenMatchEta_AfterLooseIso3H");
    hTauGenMatchEta_AfterLooseIso3H_40->Rebin(2);
    TH1F* hGenTauEta_40 = (TH1F*)f2->Get("hTauGenMatchEta");
    hGenTauEta_40->Rebin(2);
    TH1F* EffLooseIso3Hits_Eta_40 =new TH1F("EffLooseIso3Hits_Eta_40","EffLooseIso3Hits_Eta_40",50,-3,3);
    EffLooseIso3Hits_Eta_40->Divide(hTauGenMatchEta_AfterLooseIso3H_40,hGenTauEta_40, 1. ,  1. , "B");

    TH1F* hTauGenMatchPhi_AfterLooseIso3H_40 = (TH1F*)f2->Get("hTauGenMatchPhi_AfterLooseIso3H");
    TH1F* hGenTauPhi_40  = (TH1F*)f2->Get("hTauGenMatchPhi");
    TH1F* EffLooseIso3Hits_Phi_40 =new TH1F("EffLooseIso3Hits_Phi_40","EffLooseIso3Hits_Phi_40",100,-3,3);
    EffLooseIso3Hits_Phi_40->Divide(hTauGenMatchPhi_AfterLooseIso3H_40,hGenTauPhi_40, 1. ,  1. , "B");

    TH1F* hOfflinePV_AfterLooseIso3H_40 = (TH1F*)f2->Get("hOfflinePV_AfterLooseIso3H");
    TH1F* hOfflinePV_40 = (TH1F*)f2->Get("hOfflinePV");
    TH1F* EffLooseIso3Hits_NPV_40 =new TH1F("EffLooseIso3Hits_NPV","EffLooseIso3Hits_NPV",100,0,100);
    EffLooseIso3Hits_NPV_40->Divide(hOfflinePV_AfterLooseIso3H_40, hOfflinePV_40, 1. ,  1. , "B");

    /////////////////////////////8tev//////////////////////////////
    TH1F* hTauGenMatchPt_AfterLooseIso3H_8Tev = (TH1F*)f3->Get("hTauGenMatchPt_AfterLooseIso3H");
    hTauGenMatchPt_AfterLooseIso3H_8Tev->Rebin(4);
    TH1F* hGenTauPt_8Tev = (TH1F*)f3->Get("hTauGenMatchPt");
    hGenTauPt_8Tev->Rebin(4);
    TH1F* EffLooseIso3Hits_Pt_8Tev =new TH1F("EffLooseIso3Hits_Pt_8Tev","EffLooseIso3Hits_Pt_8Tev",50,0,200);
    EffLooseIso3Hits_Pt_8Tev->Divide(hTauGenMatchPt_AfterLooseIso3H_8Tev,hGenTauPt_8Tev, 1. ,  1. , "B");

    TH1F* hTauGenMatchEta_AfterLooseIso3H_8Tev = (TH1F*)f3->Get("hTauGenMatchEta_AfterLooseIso3H");
    hTauGenMatchEta_AfterLooseIso3H_8Tev->Rebin(2);
    TH1F* hGenTauEta_8Tev = (TH1F*)f3->Get("hTauGenMatchEta");
    hGenTauEta_8Tev->Rebin(2);
    TH1F* EffLooseIso3Hits_Eta_8Tev =new TH1F("EffLooseIso3Hits_Eta_8Tev","EffLooseIso3Hits_Eta_8Tev",50,-3,3);
    EffLooseIso3Hits_Eta_8Tev->Divide(hTauGenMatchEta_AfterLooseIso3H_8Tev,hGenTauEta_8Tev, 1. ,  1. , "B");

    TH1F* hTauGenMatchPhi_AfterLooseIso3H_8Tev = (TH1F*)f3->Get("hTauGenMatchPhi_AfterLooseIso3H");
    TH1F* hGenTauPhi_8Tev  = (TH1F*)f3->Get("hTauGenMatchPhi");
    TH1F* EffLooseIso3Hits_Phi_8Tev =new TH1F("EffLooseIso3Hits_Phi_8Tev","EffLooseIso3Hits_Phi_8Tev",100,-3,3);
    EffLooseIso3Hits_Phi_8Tev->Divide(hTauGenMatchPhi_AfterLooseIso3H_8Tev,hGenTauPhi_8Tev, 1. ,  1. , "B");

    TH1F* hOfflinePV_AfterLooseIso3H_8Tev = (TH1F*)f3->Get("hOfflinePV_AfterLooseIso3H");
    TH1F* hOfflinePV_8Tev = (TH1F*)f3->Get("hOfflinePV");
    TH1F* EffLooseIso3Hits_NPV_8Tev =new TH1F("EffLooseIso3Hits_NPV_8Tev","EffLooseIso3Hits_NPV_8Tev",100,0,100);
    EffLooseIso3Hits_NPV_8Tev->Divide(hOfflinePV_AfterLooseIso3H_8Tev, hOfflinePV_8Tev, 1. ,  1. , "B");

    //////////////////////Draw Eff///////////////////////////////////
    TCanvas *Eff_LooseIso3Hits = new TCanvas("Eff_LooseIso3Hits","Eff Loose Isolation 3Hits",1600,900);
    Eff_LooseIso3Hits->Divide(2,2);

    Eff_LooseIso3Hits->cd(1);
    gPad->SetGridy();
    EffLooseIso3Hits_Pt_8Tev->GetXaxis()->SetTitle("gen. P_{T}^{#tau} [GeV]");
    EffLooseIso3Hits_Pt_8Tev->GetYaxis()->SetTitle("Efficiency");

    EffLooseIso3Hits_Pt_40->SetMarkerColor(kBlue);
    EffLooseIso3Hits_Pt->SetMarkerColor(kMagenta);
    EffLooseIso3Hits_Pt_40->SetLineColor(kBlue);
    EffLooseIso3Hits_Pt->SetLineColor(kMagenta);

    EffLooseIso3Hits_Pt_8Tev->Draw("HISTE");
    EffLooseIso3Hits_Pt->Draw("HISTESAME");
    EffLooseIso3Hits_Pt_40->Draw("HISTESAME");
    EffLooseIso3Hits_Pt_8Tev->SetMinimum(0.3);
    EffLooseIso3Hits_Pt_8Tev->SetMaximum(0.9);


    Eff_LooseIso3Hits->cd(2);
    gPad->SetGridy();
    EffLooseIso3Hits_Eta_40->SetMarkerColor(kBlue);
    EffLooseIso3Hits_Eta_40->SetLineColor(kBlue);
    EffLooseIso3Hits_Eta->SetMarkerColor(kMagenta);
    EffLooseIso3Hits_Eta->SetLineColor(kMagenta);
    EffLooseIso3Hits_Eta_8Tev->Draw("HISTE");
    EffLooseIso3Hits_Eta_40->Draw("HISTESAME");
    EffLooseIso3Hits_Eta->Draw("HISTESAME");
    EffLooseIso3Hits_Eta_8Tev->GetXaxis()->SetTitle("gen. #eta_{#tau}");
    EffLooseIso3Hits_Eta_8Tev->GetYaxis()->SetTitle("Efficiency");
    EffLooseIso3Hits_Eta_8Tev->SetMinimum(0.3);
    EffLooseIso3Hits_Eta_8Tev->SetMaximum(0.9);

    Eff_LooseIso3Hits->cd(3);
    gPad->SetGridy();
    EffLooseIso3Hits_Phi_40->SetMarkerColor(kBlue);
    EffLooseIso3Hits_Phi->SetMarkerColor(kMagenta);
    EffLooseIso3Hits_Phi_40->SetLineColor(kBlue);
    EffLooseIso3Hits_Phi->SetLineColor(kMagenta);
    EffLooseIso3Hits_Phi_8Tev->Draw("HISTE");
    EffLooseIso3Hits_Phi_40->Draw("SAMEHISTE");
    EffLooseIso3Hits_Phi->Draw("SAMEHISTE");
    EffLooseIso3Hits_Phi_8Tev->GetXaxis()->SetTitle("gen. #phi_{#tau}");
    EffLooseIso3Hits_Phi_8Tev->GetYaxis()->SetTitle("Efficiency");
    EffLooseIso3Hits_Phi_8Tev->SetMinimum(0.3);
    EffLooseIso3Hits_Phi_8Tev->SetMaximum(0.9);

    Eff_LooseIso3Hits->cd(4);
    gPad->SetGridy();
    EffLooseIso3Hits_NPV_40->SetMarkerColor(kBlue);
    EffLooseIso3Hits_NPV->SetMarkerColor(kMagenta);
    EffLooseIso3Hits_NPV_40->SetLineColor(kBlue);
    EffLooseIso3Hits_NPV->SetLineColor(kMagenta);
    EffLooseIso3Hits_NPV_8Tev->GetXaxis()->SetRange(0, 70);

    EffLooseIso3Hits_NPV_40->GetXaxis()->SetRange(0, 70);
    EffLooseIso3Hits_NPV->GetXaxis()->SetRange(0, 70);

    EffLooseIso3Hits_NPV_8Tev->Draw();
    EffLooseIso3Hits_NPV_40->Draw("HISTESAME");
    EffLooseIso3Hits_NPV->Draw("HISTESAME");
    EffLooseIso3Hits_NPV_8Tev->GetXaxis()->SetTitle("N_{vtx}");
    EffLooseIso3Hits_NPV_8Tev->GetYaxis()->SetTitle("Efficiency");
    EffLooseIso3Hits_NPV_8Tev->SetMinimum(0.);
    EffLooseIso3Hits_NPV_8Tev->SetMaximum(0.9);

    TLegend* legend = new TLegend( 0.2, 0.75, 0.65, 0.9);
    legend->SetTextSize(0.047);
    legend->SetFillColor(0);
    legend->AddEntry(EffLooseIso3Hits_Phi_8Tev, "Summer12, 8 TeV");
    legend->AddEntry(EffLooseIso3Hits_Phi, "Fall13, 13 TeV, PU20, bx25");
    legend->AddEntry(EffLooseIso3Hits_Phi_40, "Fall13, 13 TeV, PU40, bx25");
    Eff_LooseIso3Hits->cd(3);
    legend->Draw("same");

    Eff_LooseIso3Hits->SaveAs("LooseIsoEff.pdf");


}
Example #25
0
void aliceReferror()
{
  cout<<endl;
  cout<<endl;
  gStyle->SetOptFit(0);

  //Fill ALice(7TeV,|y|<0.5) and CMS(2.76TeV,|y|<1) FONLL values
  cout<<"---- Fill ALice(7TeV,|y|<0.5) and CMS(2.76TeV,|y|<1) FONLL values"<<endl;

  TString infnameAlice="fonllInput/fo_Dzero_pp_7_y0p5_curve.dat";
  TString infnameAnly="fonllInput/fo_Dzero_pp_2p76_y1_curve.dat";
  ifstream getdataAlice(infnameAlice.Data());
  ifstream getdataAnly(infnameAnly.Data());

  TH1F* hptAlice = new TH1F("hptAlice","",fo_BIN_NUM,HMIN,HMAX);          TH1F* hptAnly = new TH1F("hptAnly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hminallAlice = new TH1F("hminallAlice","",fo_BIN_NUM,HMIN,HMAX);  //TH1F* hminallAnly = new TH1F("hminallAnly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hmaxallAlice = new TH1F("hmaxallAlice","",fo_BIN_NUM,HMIN,HMAX);  //TH1F* hmaxallAnly = new TH1F("hmaxllAnly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hpt11Alice = new TH1F("hpt11Alice","",fo_BIN_NUM,HMIN,HMAX);      TH1F* hpt11Anly = new TH1F("hpt11Anly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hpt55Alice = new TH1F("hpt55Alice","",fo_BIN_NUM,HMIN,HMAX);      TH1F* hpt55Anly = new TH1F("hpt55Anly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hpt22Alice = new TH1F("hpt22Alice","",fo_BIN_NUM,HMIN,HMAX);      TH1F* hpt22Anly = new TH1F("hpt22Anly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hpt21Alice = new TH1F("hpt21Alice","",fo_BIN_NUM,HMIN,HMAX);      TH1F* hpt21Anly = new TH1F("hpt21Anly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hpt12Alice = new TH1F("hpt12Alice","",fo_BIN_NUM,HMIN,HMAX);      TH1F* hpt12Anly = new TH1F("hpt12Anly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hpt15Alice = new TH1F("hpt15Alice","",fo_BIN_NUM,HMIN,HMAX);      TH1F* hpt15Anly = new TH1F("hpt15Anly","",fo_BIN_NUM,HMIN,HMAX);
  TH1F* hpt51Alice = new TH1F("hpt51Alice","",fo_BIN_NUM,HMIN,HMAX);      TH1F* hpt51Anly = new TH1F("hpt51Anly","",fo_BIN_NUM,HMIN,HMAX);

  Double_t a11_Alice[fo_BIN_NUM],a55_Alice[fo_BIN_NUM],a22_Alice[fo_BIN_NUM],a21_Alice[fo_BIN_NUM],a12_Alice[fo_BIN_NUM],a15_Alice[fo_BIN_NUM],a51_Alice[fo_BIN_NUM];
  Double_t a11_Anly[fo_BIN_NUM],a55_Anly[fo_BIN_NUM],a22_Anly[fo_BIN_NUM],a21_Anly[fo_BIN_NUM],a12_Anly[fo_BIN_NUM],a15_Anly[fo_BIN_NUM],a51_Anly[fo_BIN_NUM];
  Double_t min_all_Alice[fo_BIN_NUM],max_all_Alice[fo_BIN_NUM],min_sc_Alice[fo_BIN_NUM],max_sc_Alice[fo_BIN_NUM],min_mass_Alice[fo_BIN_NUM],max_mass_Alice[fo_BIN_NUM],min_pdf_Alice[fo_BIN_NUM],max_pdf_Alice[fo_BIN_NUM];
  Double_t min_all_Anly[fo_BIN_NUM],max_all_Anly[fo_BIN_NUM],min_sc_Anly[fo_BIN_NUM],max_sc_Anly[fo_BIN_NUM],min_mass_Anly[fo_BIN_NUM],max_mass_Anly[fo_BIN_NUM],min_pdf_Anly[fo_BIN_NUM],max_pdf_Anly[fo_BIN_NUM];
  Int_t i,j;
  Double_t tem=0.;
  Double_t pdfrac=0.557*1.e-6;
  for(i=0;i<fo_BIN_NUM;i++)
    {
      getdataAlice>>tem;
      getdataAlice>>a11_Alice[i];
      getdataAlice>>min_all_Alice[i];
      getdataAlice>>max_all_Alice[i];
      getdataAlice>>min_sc_Alice[i];
      getdataAlice>>max_sc_Alice[i];
      getdataAlice>>min_mass_Alice[i];
      getdataAlice>>max_mass_Alice[i];
      getdataAlice>>min_pdf_Alice[i];
      getdataAlice>>max_pdf_Alice[i];
      getdataAlice>>a55_Alice[i];
      getdataAlice>>a22_Alice[i];
      getdataAlice>>a21_Alice[i];
      getdataAlice>>a12_Alice[i];
      getdataAlice>>a15_Alice[i];
      getdataAlice>>a51_Alice[i];
    }
  for(i=0;i<fo_BIN_NUM;i++)
    {
      getdataAnly>>tem;
      getdataAnly>>a11_Anly[i];
      getdataAnly>>min_all_Anly[i];
      getdataAnly>>max_all_Anly[i];
      getdataAnly>>min_sc_Anly[i];
      getdataAnly>>max_sc_Anly[i];
      getdataAnly>>min_mass_Anly[i];
      getdataAnly>>max_mass_Anly[i];
      getdataAnly>>min_pdf_Anly[i];
      getdataAnly>>max_pdf_Anly[i];
      getdataAnly>>a55_Anly[i];
      getdataAnly>>a22_Anly[i];
      getdataAnly>>a21_Anly[i];
      getdataAnly>>a12_Anly[i];
      getdataAnly>>a15_Anly[i];
      getdataAnly>>a51_Anly[i];
    }
  for(i=0;i<fo_BIN_NUM;i++)
    {
      hptAlice->SetBinContent(i+1,a11_Alice[i]*pdfrac);
      hminallAlice->SetBinContent(i+1,min_all_Alice[i]*pdfrac);
      hmaxallAlice->SetBinContent(i+1,max_all_Alice[i]*pdfrac);
      hpt11Alice->SetBinContent(i+1,a11_Alice[i]*pdfrac);
      hpt55Alice->SetBinContent(i+1,a55_Alice[i]*pdfrac);
      hpt22Alice->SetBinContent(i+1,a22_Alice[i]*pdfrac);
      hpt21Alice->SetBinContent(i+1,a21_Alice[i]*pdfrac);
      hpt12Alice->SetBinContent(i+1,a12_Alice[i]*pdfrac);
      hpt15Alice->SetBinContent(i+1,a15_Alice[i]*pdfrac);
      hpt51Alice->SetBinContent(i+1,a51_Alice[i]*pdfrac);
      hptAnly->SetBinContent(i+1,a11_Anly[i]*pdfrac);
      hpt11Anly->SetBinContent(i+1,a11_Anly[i]*pdfrac);
      hpt55Anly->SetBinContent(i+1,a55_Anly[i]*pdfrac);
      hpt22Anly->SetBinContent(i+1,a22_Anly[i]*pdfrac);
      hpt21Anly->SetBinContent(i+1,a21_Anly[i]*pdfrac);
      hpt12Anly->SetBinContent(i+1,a12_Anly[i]*pdfrac);
      hpt15Anly->SetBinContent(i+1,a15_Anly[i]*pdfrac);
      hpt51Anly->SetBinContent(i+1,a51_Anly[i]*pdfrac);
    }

  //Calculate data weighted ptbin centers
  cout<<"---- Calculate data weighted ptbin centers"<<endl;
  Double_t da_bincenter[da_BIN_NUM];
  Double_t summul=0,sum=0;
  for(i=0;i<da_BIN_NUM;i++)
    {
      summul=0;
      sum=0;
      for(j=da_ptbin[i]*4;j<da_ptbin[i+1]*4;j++)
	{
	  summul+=hptAlice->GetBinContent(j+1)*hptAlice->GetBinCenter(j+1);
	  sum+=hptAlice->GetBinContent(j+1);
	}
      da_bincenter[i] = summul/sum;
    }
  
  //Back up
  TH1F* hptAliceRef=(TH1F*)hptAlice->Clone();
  hptAliceRef->SetName("hptAliceRef");
  TH1F* hptAnlyRef=(TH1F*)hptAnly->Clone();
  hptAnlyRef->SetName("hptAnlyRef");

  Double_t apt[da_BIN_NUM],aptl[da_BIN_NUM],aptlsyst[da_BIN_NUM],aptlscaling[da_BIN_NUM];
  TH1F* hptAlice_rebinalice = (TH1F*)hptAliceRef->Rebin(da_BIN_NUM,"hptAlice_rebinalice",da_ptbin);
  for(i=0;i<da_BIN_NUM;i++)
    {
      apt[i] = hptAlice_rebinalice->GetBinCenter(i+1);
      aptl[i] = hptAlice_rebinalice->GetBinWidth(i+1)/2.;
      aptlsyst[i] = 1./6.;
      aptlscaling[i] = 1./4.;
    }
  
  //Test ALICE results
  if(testAliceData)
    {
      cout<<"---- Test Alice data points"<<endl;
      Double_t asigma[da_BIN_NUM],aerrorl[da_BIN_NUM],aerrorh[da_BIN_NUM],aminall[da_BIN_NUM],amaxall[da_BIN_NUM];
      TH1F* hminallAlice_rebinalice = (TH1F*)hminallAlice->Rebin(da_BIN_NUM,"hminallAlice_rebinalice",da_ptbin);
      TH1F* hmaxallAlice_rebinalice = (TH1F*)hmaxallAlice->Rebin(da_BIN_NUM,"hmaxallAlice_rebinalice",da_ptbin);
      for(i=0;i<da_BIN_NUM;i++)
	{
	  hptAlice_rebinalice->SetBinContent(i+1,hptAlice_rebinalice->GetBinContent(i+1)/(hptAlice_rebinalice->GetBinWidth(i+1)*4));
	  asigma[i]=hptAlice_rebinalice->GetBinContent(i+1);
	  hminallAlice_rebinalice->SetBinContent(i+1,hminallAlice_rebinalice->GetBinContent(i+1)/(hminallAlice_rebinalice->GetBinWidth(i+1)*4));
	  aminall[i]=hminallAlice_rebinalice->GetBinContent(i+1);
	  hmaxallAlice_rebinalice->SetBinContent(i+1,hmaxallAlice_rebinalice->GetBinContent(i+1)/(hmaxallAlice_rebinalice->GetBinWidth(i+1)*4));
	  amaxall[i]=hmaxallAlice_rebinalice->GetBinContent(i+1);
	  aerrorl[i] = asigma[i]-aminall[i];
	  aerrorh[i] = amaxall[i]-asigma[i];
	}
      TCanvas* cReproduceAlice = new TCanvas("cReproduceAlice","",600,600);
      cReproduceAlice->SetLogy();
      TH2F* hempty_cReproduceAlice = new TH2F("hempty_cReproduceAlice","",10,0,25.,10.,0.006,1.e+3);
      hempty_cReproduceAlice->SetStats(0);
      hempty_cReproduceAlice->GetXaxis()->SetTitle("p_{t} (GeV/c)");
      hempty_cReproduceAlice->GetYaxis()->SetTitle("d#sigma(D^{0})/dp_{T}(pb GeV-1c)");
      hempty_cReproduceAlice->GetXaxis()->SetTitleOffset(1.);
      hempty_cReproduceAlice->GetYaxis()->SetTitleOffset(.9);
      hempty_cReproduceAlice->GetXaxis()->SetTitleSize(0.045);
      hempty_cReproduceAlice->GetYaxis()->SetTitleSize(0.045);
      hempty_cReproduceAlice->GetXaxis()->SetTitleFont(42);
      hempty_cReproduceAlice->GetYaxis()->SetTitleFont(42);
      hempty_cReproduceAlice->GetXaxis()->SetLabelFont(42);
      hempty_cReproduceAlice->GetYaxis()->SetLabelFont(42);
      hempty_cReproduceAlice->GetXaxis()->SetLabelSize(0.04);
      hempty_cReproduceAlice->GetYaxis()->SetLabelSize(0.04);  
      hempty_cReproduceAlice->Draw();
      TGraphAsymmErrors* gAliceFONLL = new TGraphAsymmErrors(da_BIN_NUM, apt, asigma, aptl, aptl, aerrorl, aerrorh);
      gAliceFONLL->SetFillColor(kRed);
      gAliceFONLL->SetFillStyle(3002);
      gAliceFONLL->SetLineWidth(2.);
      gAliceFONLL->SetLineColor(kRed);
      gAliceFONLL->Draw("5same");
      TGraphAsymmErrors* gAliceSyst = new TGraphAsymmErrors(da_BIN_NUM, apt, da_cs, aptlsyst, aptlsyst, da_syst_dw, da_syst_up);
      gAliceSyst->SetFillColor(0);
      gAliceSyst->SetFillStyle(0);
      gAliceSyst->SetLineWidth(2.);
      gAliceSyst->SetLineColor(kBlack);
      gAliceSyst->Draw("5same");
      TGraphAsymmErrors* gAliceStat = new TGraphAsymmErrors(da_BIN_NUM, apt, da_cs, aptl, aptl, da_stat, da_stat);
      gAliceStat->SetMarkerStyle(21);
      gAliceStat->SetMarkerColor(kBlack);
      gAliceStat->SetLineWidth(2);
      gAliceStat->SetLineColor(kBlack);
      gAliceStat->Draw("psame");
      cReproduceAlice->SaveAs(Form("plots/%s/reproduceAlice.pdf",rapi.Data()));
    }

  cout<<"---- Rebin into data ptbins"<<endl;
  TH1F* hpt11Alice_rebin = (TH1F*)hpt11Alice->Rebin(da_BIN_NUM,"hpt11Alice_rebin",da_ptbin);
  TH1F* hpt55Alice_rebin = (TH1F*)hpt55Alice->Rebin(da_BIN_NUM,"hpt55Alice_rebin",da_ptbin);
  TH1F* hpt22Alice_rebin = (TH1F*)hpt22Alice->Rebin(da_BIN_NUM,"hpt22Alice_rebin",da_ptbin);
  TH1F* hpt21Alice_rebin = (TH1F*)hpt21Alice->Rebin(da_BIN_NUM,"hpt21Alice_rebin",da_ptbin);
  TH1F* hpt12Alice_rebin = (TH1F*)hpt12Alice->Rebin(da_BIN_NUM,"hpt12Alice_rebin",da_ptbin);
  TH1F* hpt15Alice_rebin = (TH1F*)hpt15Alice->Rebin(da_BIN_NUM,"hpt15Alice_rebin",da_ptbin);
  TH1F* hpt51Alice_rebin = (TH1F*)hpt51Alice->Rebin(da_BIN_NUM,"hpt51Alice_rebin",da_ptbin);
  TH1F* hpt11Anly_rebin = (TH1F*)hpt11Anly->Rebin(da_BIN_NUM,"hpt11Anly_rebin",da_ptbin);
  TH1F* hpt55Anly_rebin = (TH1F*)hpt55Anly->Rebin(da_BIN_NUM,"hpt55Anly_rebin",da_ptbin);
  TH1F* hpt22Anly_rebin = (TH1F*)hpt22Anly->Rebin(da_BIN_NUM,"hpt22Anly_rebin",da_ptbin);
  TH1F* hpt21Anly_rebin = (TH1F*)hpt21Anly->Rebin(da_BIN_NUM,"hpt21Anly_rebin",da_ptbin);
  TH1F* hpt12Anly_rebin = (TH1F*)hpt12Anly->Rebin(da_BIN_NUM,"hpt12Anly_rebin",da_ptbin);
  TH1F* hpt15Anly_rebin = (TH1F*)hpt15Anly->Rebin(da_BIN_NUM,"hpt15Anly_rebin",da_ptbin);
  TH1F* hpt51Anly_rebin = (TH1F*)hpt51Anly->Rebin(da_BIN_NUM,"hpt51Anly_rebin",da_ptbin);

  //Calculate ratios and errors with different sets of scaling
  cout<<"---- Calculate ratios and errors with different sets of scaling"<<endl;
  TH1F* hratio11_rebin = (TH1F*)hpt11Anly_rebin->Clone();  hratio11_rebin->SetName("hratio11_rebin");  hratio11_rebin->Divide(hpt11Alice_rebin);  Double_t aratio11[da_BIN_NUM];
  TH1F* hratio55_rebin = (TH1F*)hpt55Anly_rebin->Clone();  hratio55_rebin->SetName("hratio55_rebin");  hratio55_rebin->Divide(hpt55Alice_rebin);  Double_t aratio55[da_BIN_NUM];
  TH1F* hratio22_rebin = (TH1F*)hpt22Anly_rebin->Clone();  hratio22_rebin->SetName("hratio22_rebin");  hratio22_rebin->Divide(hpt22Alice_rebin);  Double_t aratio22[da_BIN_NUM];
  TH1F* hratio21_rebin = (TH1F*)hpt21Anly_rebin->Clone();  hratio21_rebin->SetName("hratio21_rebin");  hratio21_rebin->Divide(hpt21Alice_rebin);  Double_t aratio21[da_BIN_NUM];
  TH1F* hratio12_rebin = (TH1F*)hpt12Anly_rebin->Clone();  hratio12_rebin->SetName("hratio12_rebin");  hratio12_rebin->Divide(hpt12Alice_rebin);  Double_t aratio12[da_BIN_NUM];
  TH1F* hratio15_rebin = (TH1F*)hpt15Anly_rebin->Clone();  hratio15_rebin->SetName("hratio15_rebin");  hratio15_rebin->Divide(hpt15Alice_rebin);  Double_t aratio15[da_BIN_NUM];
  TH1F* hratio51_rebin = (TH1F*)hpt51Anly_rebin->Clone();  hratio51_rebin->SetName("hratio51_rebin");  hratio51_rebin->Divide(hpt51Alice_rebin);  Double_t aratio51[da_BIN_NUM];
  Double_t aratioErrup[da_BIN_NUM], aratioErrdw[da_BIN_NUM];

  for(i=0;i<da_BIN_NUM;i++)
    {
      Double_t sortup=-1,sortdw=10000;
      aratio11[i] = hratio11_rebin->GetBinContent(i+1);  if(aratio11[i]>sortup){sortup=aratio11[i];}  if(aratio11[i]<sortdw){sortdw=aratio11[i];}
      aratio55[i] = hratio55_rebin->GetBinContent(i+1);  if(aratio55[i]>sortup){sortup=aratio55[i];}  if(aratio55[i]<sortdw){sortdw=aratio55[i];}
      aratio22[i] = hratio22_rebin->GetBinContent(i+1);  if(aratio22[i]>sortup){sortup=aratio22[i];}  if(aratio22[i]<sortdw){sortdw=aratio22[i];}
      aratio21[i] = hratio21_rebin->GetBinContent(i+1);  if(aratio21[i]>sortup){sortup=aratio21[i];}  if(aratio21[i]<sortdw){sortdw=aratio21[i];}
      aratio12[i] = hratio12_rebin->GetBinContent(i+1);  if(aratio12[i]>sortup){sortup=aratio12[i];}  if(aratio12[i]<sortdw){sortdw=aratio12[i];}
      aratio15[i] = hratio15_rebin->GetBinContent(i+1);  if(aratio15[i]>sortup){sortup=aratio15[i];}  if(aratio15[i]<sortdw){sortdw=aratio15[i];}
      aratio51[i] = hratio51_rebin->GetBinContent(i+1);  if(aratio51[i]>sortup){sortup=aratio51[i];}  if(aratio51[i]<sortdw){sortdw=aratio51[i];}
      aratioErrup[i] = sortup-aratio11[i];
      aratioErrdw[i] = aratio11[i]-sortdw;
    }
  TGraph* gratio11 = new TGraph(da_BIN_NUM,da_ptctr,aratio11);
  TGraph* gratio55 = new TGraph(da_BIN_NUM,da_ptctr,aratio55);
  TGraph* gratio22 = new TGraph(da_BIN_NUM,da_ptctr,aratio22);
  TGraph* gratio21 = new TGraph(da_BIN_NUM,da_ptctr,aratio21);
  TGraph* gratio12 = new TGraph(da_BIN_NUM,da_ptctr,aratio12);
  TGraph* gratio15 = new TGraph(da_BIN_NUM,da_ptctr,aratio15);
  TGraph* gratio51 = new TGraph(da_BIN_NUM,da_ptctr,aratio51);

  cout<<"  -- Plot FONLL ratio center values"<<endl;
  TCanvas* ccenterRatio = new TCanvas("ccenterRatio","",700,500);
  TH2F* hempty_ccenterRatio = new TH2F("hempty_ccenterRatio","",10,0,17.,10.,0.2,2.2);
  hempty_ccenterRatio->SetStats(0);
  hempty_ccenterRatio->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hempty_ccenterRatio->GetYaxis()->SetTitle("#sigma(2.76TeV,|y|<1)/#sigma(7TeV.|y|<0.5)");
  hempty_ccenterRatio->GetXaxis()->SetTitleOffset(1.);
  hempty_ccenterRatio->GetYaxis()->SetTitleOffset(.9);
  hempty_ccenterRatio->GetXaxis()->SetTitleSize(0.045);
  hempty_ccenterRatio->GetYaxis()->SetTitleSize(0.045);
  hempty_ccenterRatio->GetXaxis()->SetTitleFont(42);
  hempty_ccenterRatio->GetYaxis()->SetTitleFont(42);
  hempty_ccenterRatio->GetXaxis()->SetLabelFont(42);
  hempty_ccenterRatio->GetYaxis()->SetLabelFont(42);
  hempty_ccenterRatio->GetXaxis()->SetLabelSize(0.04);
  hempty_ccenterRatio->GetYaxis()->SetLabelSize(0.04);
  hempty_ccenterRatio->Draw();
  gratio11->SetLineColor(1);   gratio11->SetLineWidth(2);  gratio11->Draw("lsame");
  ccenterRatio->SaveAs(Form("plots/%s/cratioCenter.pdf",rapi.Data()));

  cout<<"  -- Plot FONLL ratios with different sets of scaling"<<endl;  
  TCanvas* ccompareRatio = new TCanvas("ccompareRatio","",700,500);
  TH2F* hempty_ccompareRatio = new TH2F("hempty_ccompareRatio","",10,0,17.,10.,0.2,2.2);
  hempty_ccompareRatio->SetStats(0);
  hempty_ccompareRatio->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hempty_ccompareRatio->GetYaxis()->SetTitle("#sigma(2.76TeV,|y|<1)/#sigma(7TeV.|y|<0.5)");
  hempty_ccompareRatio->GetXaxis()->SetTitleOffset(1.);
  hempty_ccompareRatio->GetYaxis()->SetTitleOffset(.9);
  hempty_ccompareRatio->GetXaxis()->SetTitleSize(0.045);
  hempty_ccompareRatio->GetYaxis()->SetTitleSize(0.045);
  hempty_ccompareRatio->GetXaxis()->SetTitleFont(42);
  hempty_ccompareRatio->GetYaxis()->SetTitleFont(42);
  hempty_ccompareRatio->GetXaxis()->SetLabelFont(42);
  hempty_ccompareRatio->GetYaxis()->SetLabelFont(42);
  hempty_ccompareRatio->GetXaxis()->SetLabelSize(0.04);
  hempty_ccompareRatio->GetYaxis()->SetLabelSize(0.04);
  hempty_ccompareRatio->Draw();
  TGraphAsymmErrors* gratioGlobal = new TGraphAsymmErrors(da_BIN_NUM, apt, aratio11, aptl, aptl, aratioErrdw, aratioErrup);
  gratioGlobal->SetFillStyle(1001);
  gratioGlobal->SetFillColor(kYellow-9);
  gratioGlobal->Draw("2same");
  gratio11->SetLineColor(1);   gratio11->SetLineWidth(2);  gratio11->Draw("lsame");
  gratio55->SetLineColor(3);   gratio55->SetLineWidth(2);  gratio55->Draw("lsame");
  gratio22->SetLineColor(9);   gratio22->SetLineWidth(2);  gratio22->Draw("lsame");
  gratio21->SetLineColor(47);  gratio21->SetLineWidth(2);  gratio21->Draw("lsame");
  gratio12->SetLineColor(6);   gratio12->SetLineWidth(2);  gratio12->Draw("lsame");
  gratio15->SetLineColor(7);   gratio15->SetLineWidth(2);  gratio15->Draw("lsame");
  gratio51->SetLineColor(43);  gratio51->SetLineWidth(2);  gratio51->Draw("lsame");
  TLegend* legratioScaling = new TLegend(0.60,0.50,0.80,0.89);
  legratioScaling->SetFillColor(0);
  legratioScaling->SetBorderSize(0);
  legratioScaling->AddEntry((TObject*)0,"#mu_{F}/#mu_{0}  #mu_{R}/#mu_{0}","");
  legratioScaling->AddEntry(gratio11,"  1       1","l");
  legratioScaling->AddEntry(gratio55," 0.5     0.5","l");
  legratioScaling->AddEntry(gratio22,"  2       2","l");
  legratioScaling->AddEntry(gratio21,"  2       1","l");
  legratioScaling->AddEntry(gratio12,"  1       2","l");
  legratioScaling->AddEntry(gratio15,"  1      0.5","l");
  legratioScaling->AddEntry(gratio51," 0.5      1","l");
  legratioScaling->Draw("same");
  ccompareRatio->SaveAs(Form("plots/%s/cratioGlobal.pdf",rapi.Data()));

  //Plot global relative FONLL ratio errors
  cout<<"  -- Plot global relative FONLL ratio errors"<<endl;
  Double_t aratioRela[da_BIN_NUM],aratioErrdwRela[da_BIN_NUM],aratioErrupRela[da_BIN_NUM];
  for(i=0;i<da_BIN_NUM;i++)
    {
      aratioRela[i] = 0;
      aratioErrdwRela[i] = aratioErrdw[i]/aratio11[i];
      aratioErrupRela[i] = aratioErrup[i]/aratio11[i];
    }
  TCanvas* cratioRela = new TCanvas("cratioRela","",700,500);
  cratioRela->SetGrid();
  TH2F* hempty_cratioRela = new TH2F("hempty_cratioRela","",10,1,16.,10.,-1,1);
  hempty_cratioRela->SetStats(0);
  hempty_cratioRela->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hempty_cratioRela->GetYaxis()->SetTitle("#sigma(2.76TeV,|y|<1.)/#sigma(7TeV,|y|<0.5) Relative unc.");
  hempty_cratioRela->GetXaxis()->SetTitleOffset(1.);
  hempty_cratioRela->GetYaxis()->SetTitleOffset(.9);
  hempty_cratioRela->GetXaxis()->SetTitleSize(0.045);
  hempty_cratioRela->GetYaxis()->SetTitleSize(0.045);
  hempty_cratioRela->GetXaxis()->SetTitleFont(42);
  hempty_cratioRela->GetYaxis()->SetTitleFont(42);
  hempty_cratioRela->GetXaxis()->SetLabelFont(42);
  hempty_cratioRela->GetYaxis()->SetLabelFont(42);
  hempty_cratioRela->GetXaxis()->SetLabelSize(0.04);
  hempty_cratioRela->GetYaxis()->SetLabelSize(0.04);
  hempty_cratioRela->Draw();
  TGraphAsymmErrors* gratioRela = new TGraphAsymmErrors(da_BIN_NUM, apt, aratioRela, aptl, aptl, aratioErrdwRela, aratioErrupRela);
  gratioRela->SetFillStyle(3001);
  gratioRela->SetFillColor(8);
  gratioRela->Draw("2same");
  cratioRela->SaveAs(Form("plots/%s/cratioRela.pdf",rapi.Data()));

  //Scale ALICE data points and propagate uncertainties
  cout<<"---- Scale ALice data center values and propagate uncertainties"<<endl;
  Double_t acrosssec[da_BIN_NUM],aminErr[da_BIN_NUM],amaxErr[da_BIN_NUM],aminErrrel[da_BIN_NUM],amaxErrrel[da_BIN_NUM],aminErrsyst[da_BIN_NUM],amaxErrsyst[da_BIN_NUM],aminErrstat[da_BIN_NUM],amaxErrstat[da_BIN_NUM],aminErrscaling[da_BIN_NUM],amaxErrscaling[da_BIN_NUM];
  for(i=0;i<da_BIN_NUM;i++)
    {
      acrosssec[i] = da_cs[i]*aratio11[i];
      aminErr[i] = acrosssec[i]*TMath::Sqrt((da_syst_dw[i]*da_syst_dw[i]+da_stat[i]*da_stat[i])/(da_cs[i]*da_cs[i])
					  + aratioErrdwRela[i]*aratioErrdwRela[i]);
      aminErrrel[i] = aminErr[i]/acrosssec[i];
      amaxErr[i] = acrosssec[i]*TMath::Sqrt((da_syst_up[i]*da_syst_up[i]+da_stat[i]*da_stat[i])/(da_cs[i]*da_cs[i])
					  + aratioErrupRela[i]*aratioErrupRela[i]);
      amaxErrrel[i] = amaxErr[i]/acrosssec[i];
      aminErrsyst[i] = acrosssec[i]*(da_syst_dw[i]/da_cs[i]);
      amaxErrsyst[i] = acrosssec[i]*(da_syst_up[i]/da_cs[i]);
      aminErrstat[i] = acrosssec[i]*(da_stat[i]/da_cs[i]);
      amaxErrstat[i] = acrosssec[i]*(da_stat[i]/da_cs[i]);
      aminErrscaling[i] = acrosssec[i]*aratioErrdwRela[i];
      amaxErrscaling[i] = acrosssec[i]*aratioErrupRela[i];
    }
  cout<<"---- Plot scaled data with different components of uncertainties"<<endl;
  TCanvas* cErrors = new TCanvas("cErrors","",500,500);
  cErrors->SetLogy();
  TH2F* hempty_cErrors = new TH2F("hempty_cErrors","",10,0,17.,10.,1.e-2,1.e+3);
  hempty_cErrors->SetStats(0);
  hempty_cErrors->GetXaxis()->SetTitle("p_{t} (GeV/c)");
  hempty_cErrors->GetYaxis()->SetTitle("d#sigma(D^{0})/dp_{T}(#mub GeV-1c)");
  hempty_cErrors->GetXaxis()->SetTitleOffset(1.);
  hempty_cErrors->GetYaxis()->SetTitleOffset(.9);
  hempty_cErrors->GetXaxis()->SetTitleSize(0.045);
  hempty_cErrors->GetYaxis()->SetTitleSize(0.045);
  hempty_cErrors->GetXaxis()->SetTitleFont(42);
  hempty_cErrors->GetYaxis()->SetTitleFont(42);
  hempty_cErrors->GetXaxis()->SetLabelFont(42);
  hempty_cErrors->GetYaxis()->SetLabelFont(42);
  hempty_cErrors->GetXaxis()->SetLabelSize(0.04);
  hempty_cErrors->GetYaxis()->SetLabelSize(0.04);
  hempty_cErrors->Draw();
  for(i=0;i<da_BIN_NUM;i++)
   {
     aptlscaling[i] = 1./3.;
   }
  TGraphAsymmErrors* gErrScaling = new TGraphAsymmErrors(da_BIN_NUM, da_ptctr, acrosssec, aptlscaling, aptlscaling, aminErrscaling, amaxErrscaling); gErrScaling->SetName("gErrScaling");
  gErrScaling->SetLineWidth(0);
  gErrScaling->SetFillStyle(1001);
  gErrScaling->SetFillColor(kMagenta-7);
  gErrScaling->Draw("2same");
  TGraphAsymmErrors* gErrTotal = new TGraphAsymmErrors(da_BIN_NUM, da_ptctr, acrosssec, aptl, aptl, aminErr, amaxErr);
  gErrTotal->SetFillStyle(0);
  gErrTotal->SetLineColor(kMagenta+2);
  gErrTotal->SetLineWidth(2);
  gErrTotal->Draw("5same");
  TGraphAsymmErrors* gErrSyst = new TGraphAsymmErrors(da_BIN_NUM, da_ptctr, acrosssec, aptlsyst, aptlsyst, aminErrsyst, amaxErrsyst);
  gErrSyst->SetFillStyle(0);
  gErrSyst->SetLineColor(kAzure-2);
  gErrSyst->SetLineWidth(2.);
  gErrSyst->Draw("5same");
  TGraphAsymmErrors* gErrStat = new TGraphAsymmErrors(da_BIN_NUM, da_ptctr, acrosssec, aptl, aptl, aminErrstat, amaxErrstat);
  gErrStat->SetMarkerSize(0);
  gErrStat->SetLineColor(kAzure-2);
  gErrStat->SetLineWidth(2.);
  gErrStat->Draw("psame");
  TGraph* gErr = new TGraph(da_BIN_NUM, da_ptctr, acrosssec);
  gErr->SetMarkerStyle(20);
  gErr->SetMarkerSize(1.);
  gErr->SetMarkerColor(kMagenta+2);
  gErr->Draw("psame");
  TLegend* legErrors = new TLegend(0.60,0.70,0.90,0.90);
  legErrors->SetFillColor(0);
  legErrors->SetBorderSize(0);
  legErrors->AddEntry(gErrTotal,"Total unc.","f");
  legErrors->AddEntry(gErrSyst,"Data syst. unc.","f");
  legErrors->AddEntry(gErrStat,"Data stat. unc.","lep");
  legErrors->AddEntry(gErrScaling,"FONLL scaling unc.","f");
  legErrors->Draw("same");
  cErrors->SaveAs(Form("plots/%s/cErrors.pdf",rapi.Data()));

  //Print out scaled data points center values and total uncert.
  cout<<"---- Print out scaled data points center values and total uncert."<<endl;
  Int_t q=0;
  cout<<endl;
  cout<<"  -- Scaled reference before rebin"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"pT bins[]";
  cout<<" = {";
  for(q=0;q<da_BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      TString sptbin = Form("(%.1f,%.1f)",da_ptbin[q],da_ptbin[q+1]);
      cout<<setiosflags(std::ios::left)<<setw(12)<<sptbin;
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Center value[]";
  cout<<" = {";
  for(q=0;q<da_BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      cout<<setiosflags(std::ios::left)<<setw(12)<<acrosssec[q];
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Up errors[]";
  cout<<" = {";
  for(q=0;q<da_BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      cout<<setiosflags(std::ios::left)<<setw(12)<<amaxErr[q];
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Relative Up errors[]";
  cout<<" = {";
  for(q=0;q<da_BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      TString percsign = "%";
      TString sperc = Form("%.2f%s",amaxErrrel[q]*100.,percsign.Data());
      cout<<setiosflags(std::ios::left)<<setw(12)<<sperc;
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Dw errors[]";
  cout<<" = {";
  for(q=0;q<da_BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      cout<<setiosflags(std::ios::left)<<setw(12)<<aminErr[q];
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Relative Dw errors[]";
  cout<<" = {";
  for(q=0;q<da_BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      TString percsign = "%";
      TString sperc = Form("%.2f%s",aminErrrel[q]*100.,percsign.Data());
      cout<<setiosflags(std::ios::left)<<setw(12)<<sperc;
    }
  cout<<"};"<<endl;
  cout<<endl;

  //Plot and fit scaled data points
  cout<<"---- Plot and fit scaled data"<<endl;
  cout<<"  -- Plot scaled data with total uncertainty"<<endl;
  Double_t iexl[da_BIN_NUM],iexr[da_BIN_NUM];
  for(i=0;i<da_BIN_NUM;i++)
    {
      iexl[i] = da_bincenter[i]-da_ptbin[i];
      iexr[i] = da_ptbin[i+1]-da_bincenter[i];
    }
  TGraphAsymmErrors* gcrosssec_rescaled = new TGraphAsymmErrors(da_BIN_NUM, da_bincenter, acrosssec, iexl, iexr, aminErr, amaxErr);
  gcrosssec_rescaled->SetMarkerStyle(20);
  gcrosssec_rescaled->SetMarkerSize(0.7);
  gcrosssec_rescaled->SetMarkerColor(kBlack);
  gcrosssec_rescaled->SetLineWidth(2);
  gcrosssec_rescaled->SetLineColor(kBlack);
  TCanvas* crescaled =  new TCanvas("crescaled","",400,400);
  crescaled->SetLogy();
  TH2F* hempty_crescaled=new TH2F("hempty_crescaled","",10,0,20.,10.,1.e-2,1.e+3);
  hempty_crescaled->SetStats(0);
  hempty_crescaled->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hempty_crescaled->GetYaxis()->SetTitle("Scaled d#sigma(D^{0})/dp_{T}(#mub GeV-1c)");
  hempty_crescaled->GetXaxis()->SetTitleOffset(1.);
  hempty_crescaled->GetYaxis()->SetTitleOffset(.9);
  hempty_crescaled->GetXaxis()->SetTitleSize(0.045);
  hempty_crescaled->GetYaxis()->SetTitleSize(0.045);
  hempty_crescaled->GetXaxis()->SetTitleFont(42);
  hempty_crescaled->GetYaxis()->SetTitleFont(42);
  hempty_crescaled->GetXaxis()->SetLabelFont(42);
  hempty_crescaled->GetYaxis()->SetLabelFont(42);
  hempty_crescaled->GetXaxis()->SetLabelSize(0.04);
  hempty_crescaled->GetYaxis()->SetLabelSize(0.04);
  hempty_crescaled->Draw();
  gcrosssec_rescaled->Draw("psame");
  TLegend* legcrosssec_rescaled = new TLegend(0.60,0.80,0.90,0.90);
  legcrosssec_rescaled->SetFillColor(0);
  legcrosssec_rescaled->SetBorderSize(0);
  legcrosssec_rescaled->AddEntry(gcrosssec_rescaled,"Total unc.","lep");
  legcrosssec_rescaled->Draw("same");

  //Fit scaled data points
  cout<<"  -- Fit scaled data"<<endl;
  TF1* fdata = new TF1("fdata","pow(10,[0]*exp([1]*x)+[2])",da_ptbin[0],da_ptbin[da_BIN_NUM]);
  //fdata->SetParameter(1,-0.055);
  fdata->SetParLimits(1,-0.100,-0.055);
  fdata->SetParLimits(0,5.,8.);
  fdata->SetParLimits(2,-4.,-2.);

  //TF1* fdata = new TF1("fdata","pow(10,[0]*exp([1]*x)+[2])",da_ptbin[0],da_ptbin[da_BIN_NUM]);
  //fdata->SetParLimits(1,-0.070,-0.055);
  //fdata->SetParLimits(0,5.,7.);
  //fdata->SetParLimits(2,-4.,-3.);

  //TF1* fdata = new TF1("fdata"," exp([1]+[2]*x+[3]*x*x+[4]*x*x*x)",da_ptbin[0],da_ptbin[da_BIN_NUM]);
  //fdata->SetParameter(1,6.91);
  //fdata->SetParameter(2,-0.72);
  //fdata->SetParLimits(3,-0.01,0.008);
  //fdata->SetParLimits(4,0.0008,0.0012);
  gcrosssec_rescaled->Fit("fdata","q","",da_ptbin[1],da_ptbin[da_BIN_NUM]);
  cout<<fdata->GetParameter(0)<<"  "<<fdata->GetParameter(1)<<"  "<<fdata->GetParameter(2)<<"  "<<fdata->GetParameter(3)<<endl;
  crescaled->SaveAs(Form("plots/%s/rescaled.pdf",rapi.Data()));

  //Rebin into 2.76TeV PbPb ptbins
  cout<<"---- Rebin into 2.76TeV PbPb ptbins"<<endl;
  TH1F* hfitref = new TH1F("hfitref","",BIN_NUM,ptbin);
  TH1F* hfitreffitDoublecheck = new TH1F("hfitreffitDoublecheck","",da_BIN_NUM,da_ptbin);
  Double_t integ;
  Double_t afinalsc[BIN_NUM],afinapt[BIN_NUM],afinaptl[BIN_NUM];
  Double_t afinalupWeighted[BIN_NUM],afinaldwWeighted[BIN_NUM],afinaluprelWeighted[BIN_NUM],afinaldwrelWeighted[BIN_NUM];
  Double_t afinalupUnWeighted[BIN_NUM],afinaldwUnWeighted[BIN_NUM],afinaluprelUnWeighted[BIN_NUM],afinaldwrelUnWeighted[BIN_NUM];
  Double_t afitDoublecheck[da_BIN_NUM];

  //Calculate error rebin fraction
  cout<<"  -- Calculate error rebin fraction"<<endl;
  Double_t afracWeighted[BIN_NUM][COB_NUM],afracUnWeighted[BIN_NUM][COB_NUM];
  for(i=0;i<BIN_NUM;i++)
    {
      for(j=0;j<COB_NUM;j++)
	{
	  afracWeighted[i][j]=0;
	  afracUnWeighted[i][j]=0;
	}
    }
  for(i=0;i<BIN_NUM;i++)
    {
      for(j=0;j<COB_NUM;j++)
	{
	  if(ind[i][j]>-1)
	    {
	      afracWeighted[i][j] = fdata->Integral(lowridge[i][j],highridge[i][j]) / fdata->Integral(ptbin[i],ptbin[i+1]);
	      afracUnWeighted[i][j] = (highridge[i][j]-lowridge[i][j]) / (ptbin[i+1]-ptbin[i]);
	    }
	}
    }
  cout<<"  -- Rebin center value by fitting function"<<endl;
  cout<<"  -- Rebin uncertainties by statistic weight"<<endl;
  for(i=0;i<da_BIN_NUM;i++)
    {
      integ = fdata->Integral(da_ptbin[i],da_ptbin[i+1])/hfitreffitDoublecheck->GetBinWidth(i+1);
      afitDoublecheck[i] = integ/acrosssec[i];
    }
  TGraph* gfitDoublecheck = new TGraph(da_BIN_NUM,da_ptctr,afitDoublecheck);  
  TCanvas* cfitDoublecheck = new TCanvas("cfitDoublecheck","",500,500);
  TH2F* hempty_cfitDoublecheck = new TH2F("hempty_cfitDoublecheck","",10,0,17.,10.,0.2,2.2);
  hempty_cfitDoublecheck->SetStats(0);
  hempty_cfitDoublecheck->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hempty_cfitDoublecheck->GetYaxis()->SetTitle("#sigma(scaled data)/#sigma(rebin by fit)");
  hempty_cfitDoublecheck->GetXaxis()->SetTitleOffset(1.);
  hempty_cfitDoublecheck->GetYaxis()->SetTitleOffset(.9);
  hempty_cfitDoublecheck->GetXaxis()->SetTitleSize(0.045);
  hempty_cfitDoublecheck->GetYaxis()->SetTitleSize(0.045);
  hempty_cfitDoublecheck->GetXaxis()->SetTitleFont(42);
  hempty_cfitDoublecheck->GetYaxis()->SetTitleFont(42);
  hempty_cfitDoublecheck->GetXaxis()->SetLabelFont(42);
  hempty_cfitDoublecheck->GetYaxis()->SetLabelFont(42);
  hempty_cfitDoublecheck->GetXaxis()->SetLabelSize(0.04);
  hempty_cfitDoublecheck->GetYaxis()->SetLabelSize(0.04);
  hempty_cfitDoublecheck->Draw();
  gfitDoublecheck->SetMarkerStyle(2);   gfitDoublecheck->SetMarkerSize(2);  gfitDoublecheck->Draw("psame");
  cfitDoublecheck->SaveAs(Form("plots/%s/cfitDoublecheck.pdf",rapi.Data()));


  for(i=0;i<BIN_NUM;i++)
    {
      integ = fdata->Integral(ptbin[i],ptbin[i+1])/hfitref->GetBinWidth(i+1);
      afinalsc[i] = integ;
      hfitref->SetBinContent(i+1,integ);
      afinalupWeighted[i]=0;  afinalupUnWeighted[i]=0;
      afinaldwWeighted[i]=0;  afinaldwUnWeighted[i]=0;
      for(j=0;j<COB_NUM;j++)
	{
	  if(ind[i][j]<0) continue;
	  afinaldwrelWeighted[i]+=aminErrrel[ind[i][j]]*afracWeighted[i][j];
	  afinaldwWeighted[i] = afinaldwrelWeighted[i]*afinalsc[i];
	  afinaluprelWeighted[i]+=amaxErrrel[ind[i][j]]*afracWeighted[i][j];
	  afinalupWeighted[i] = afinaluprelWeighted[i]*afinalsc[i];
	  afinaldwrelUnWeighted[i]+=aminErrrel[ind[i][j]]*afracUnWeighted[i][j];
	  afinaldwUnWeighted[i] = afinaldwrelUnWeighted[i]*afinalsc[i];
	  afinaluprelUnWeighted[i]+=amaxErrrel[ind[i][j]]*afracUnWeighted[i][j];
	  afinalupUnWeighted[i] = afinaluprelUnWeighted[i]*afinalsc[i];
	}
      afinapt[i] = hfitref->GetBinCenter(i+1);
      afinaptl[i] = hfitref->GetBinWidth(i+1)/2.;
    }



  //Print out 2.76TeV data-driven pp reference values
  cout<<"---- Print out 2.76TeV data-driven pp reference results"<<endl;
  cout<<endl;
  //weighted
  cout<<"  -- Final reference after rebin"<<endl;
  if(displayAreaUnweighted) cout<<"  -- Area Weighted"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"pT bins[]";
  cout<<" = {";
  for(q=0;q<BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      TString sptbin = Form("(%.1f,%.1f)",ptbin[q],ptbin[q+1]);
      cout<<setiosflags(std::ios::left)<<setw(12)<<sptbin;
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Center value[]";
  cout<<" = {";
  for(q=0;q<BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      cout<<setiosflags(std::ios::left)<<setw(12)<<afinalsc[q];
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Up errors[]";
  cout<<" = {";
  for(q=0;q<BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      cout<<setiosflags(std::ios::left)<<setw(12)<<afinalupWeighted[q];
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Relative Up errors[]";
  cout<<" = {";
  for(q=0;q<BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      TString percsign = "%";
      TString sperc = Form("%.2f%s",afinaluprelWeighted[q]*100,percsign.Data());
      cout<<setiosflags(std::ios::left)<<setw(12)<<sperc;
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Dw errors[]";
  cout<<" = {";
  for(q=0;q<BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      cout<<setiosflags(std::ios::left)<<setw(12)<<afinaldwWeighted[q];
    }
  cout<<"};"<<endl;
  cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Relative Dw errors[]";
  cout<<" = {";
  for(q=0;q<BIN_NUM;q++)
    {
      if(q!=0) cout<<", ";
      TString percsign = "%";
      TString sperc = Form("%.2f%s",afinaldwrelWeighted[q]*100,percsign.Data());
      cout<<setiosflags(std::ios::left)<<setw(12)<<sperc;
    }
  cout<<"};"<<endl;
  //unweighted
  if(displayAreaUnweighted)
    {
      cout<<"  -- Area UnWeighted"<<endl;
      cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"pT bins[]";
      cout<<" = {";
      for(q=0;q<BIN_NUM;q++)
	{
	  if(q!=0) cout<<", ";
	  TString sptbin = Form("(%.1f,%.1f)",ptbin[q],ptbin[q+1]);
	  cout<<setiosflags(std::ios::left)<<setw(12)<<sptbin;
	}
      cout<<"};"<<endl;
      cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Center value[]";
      cout<<" = {";
      for(q=0;q<BIN_NUM;q++)
	{
	  if(q!=0) cout<<", ";
	  cout<<setiosflags(std::ios::left)<<setw(12)<<afinalsc[q];
	}
      cout<<"};"<<endl;
      cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Up errors[]";
      cout<<" = {";
      for(q=0;q<BIN_NUM;q++)
	{
	  if(q!=0) cout<<", ";
	  cout<<setiosflags(std::ios::left)<<setw(12)<<afinalupUnWeighted[q];
	}
      cout<<"};"<<endl;
      cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Relative Up errors[]";
      cout<<" = {";
      for(q=0;q<BIN_NUM;q++)
	{
	  if(q!=0) cout<<", ";
	  TString percsign = "%";
	  TString sperc = Form("%.2f%s",afinaluprelUnWeighted[q]*100,percsign.Data());
	  cout<<setiosflags(std::ios::left)<<setw(12)<<sperc;
	}
      cout<<"};"<<endl;
      cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Dw errors[]";
      cout<<" = {";
      for(q=0;q<BIN_NUM;q++)
	{
	  if(q!=0) cout<<", ";
	  cout<<setiosflags(std::ios::left)<<setw(12)<<afinaldwUnWeighted[q];
	}
      cout<<"};"<<endl;
      cout<<setiosflags(std::ios::left)<<"     "<<setw(20)<<"Relative Dw errors[]";
      cout<<" = {";
      for(q=0;q<BIN_NUM;q++)
	{
	  if(q!=0) cout<<", ";
	  TString percsign = "%";
	  TString sperc = Form("%.2f%s",afinaldwrelUnWeighted[q]*100,percsign.Data());
	  cout<<setiosflags(std::ios::left)<<setw(12)<<sperc;
	}
      cout<<"};"<<endl;
    }
  cout<<endl;
  
  //Plot 2.76TeV data-driven pp reference
  cout<<"---- Plot rebinned 2.76TeV data-driven pp reference"<<endl;
  TGraphAsymmErrors* gfinalref = new TGraphAsymmErrors(BIN_NUM, afinapt, afinalsc, afinaptl, afinaptl, afinaldwWeighted, afinalupWeighted);
  gfinalref->SetMarkerStyle(20);
  gfinalref->SetMarkerSize(0.7);
  gfinalref->SetMarkerColor(kBlack);
  gfinalref->SetLineWidth(2);
  gfinalref->SetLineColor(kBlack);
  TCanvas* cfinalref = new TCanvas("cfinalref","",400,400);
  cfinalref->SetLogy();
  TH2F* hempty_cfinalref = new TH2F("hempty_cfinalref","",10,0,20.,10.,1.e-2,1.e+3);
  hempty_cfinalref->SetStats(0);
  hempty_cfinalref->GetXaxis()->SetTitle("p_{t} (GeV/c)");
  hempty_cfinalref->GetYaxis()->SetTitle("Fitted d#sigma(D^{0})/dp_{T}(#mub/(GeV/c))");
  hempty_cfinalref->GetXaxis()->SetTitleOffset(1.);
  hempty_cfinalref->GetYaxis()->SetTitleOffset(.9);
  hempty_cfinalref->GetXaxis()->SetTitleSize(0.045);
  hempty_cfinalref->GetYaxis()->SetTitleSize(0.045);
  hempty_cfinalref->GetXaxis()->SetTitleFont(42);
  hempty_cfinalref->GetYaxis()->SetTitleFont(42);
  hempty_cfinalref->GetXaxis()->SetLabelFont(42);
  hempty_cfinalref->GetYaxis()->SetLabelFont(42);
  hempty_cfinalref->GetXaxis()->SetLabelSize(0.04);
  hempty_cfinalref->GetYaxis()->SetLabelSize(0.04);  
  hempty_cfinalref->Draw();
  gfinalref->Draw("psame");
  cfinalref->SaveAs(Form("plots/%s/finalref.pdf",rapi.Data()));
  
  //Plot ratio of data-driven pp reference and pure FONLL
  cout<<"---- Plot ratio of data-driven pp reference and FONLL"<<endl;
  TH1F* hptAnlyRef_rebin = (TH1F*)hptAnlyRef->Rebin(BIN_NUM,"hptAnlyRef_rebin",ptbin);
  for(i=0;i<BIN_NUM;i++)
    {
      hptAnlyRef_rebin->SetBinContent(i+1,hptAnlyRef_rebin->GetBinContent(i+1)/(hptAnlyRef_rebin->GetBinWidth(i+1)*4));      
    }
  Double_t aratiosc[BIN_NUM],aratioup[BIN_NUM],aratiodw[BIN_NUM];
  for(i=0;i<BIN_NUM;i++)
    {
      aratiosc[i] = afinalsc[i]/hptAnlyRef_rebin->GetBinContent(i+1);
      aratioup[i] = afinalupWeighted[i]/hptAnlyRef_rebin->GetBinContent(i+1);
      aratiodw[i] = afinaldwWeighted[i]/hptAnlyRef_rebin->GetBinContent(i+1);
    }
  TGraphAsymmErrors* gratioref = new TGraphAsymmErrors(BIN_NUM, afinapt, aratiosc, afinaptl, afinaptl, aratiodw, aratioup);
  gratioref->SetMarkerStyle(20);
  gratioref->SetMarkerSize(0.7);
  gratioref->SetMarkerColor(kBlack);
  gratioref->SetLineWidth(2);
  gratioref->SetLineColor(kBlack);
  TCanvas* cratioref = new TCanvas("cratioref","",400,400);
  TH2F* hempty_cratioref = new TH2F("hempty_cratioref","",10,0,18.,10.,0.,3.5);
  hempty_cratioref->SetStats(0);
  hempty_cratioref->GetXaxis()->SetTitle("p_{T} (GeV/c)");
  hempty_cratioref->GetYaxis()->SetTitle("data/FONLL");
  hempty_cratioref->GetXaxis()->SetTitleOffset(1.);
  hempty_cratioref->GetYaxis()->SetTitleOffset(.9);
  hempty_cratioref->GetXaxis()->SetTitleSize(0.045);
  hempty_cratioref->GetYaxis()->SetTitleSize(0.045);
  hempty_cratioref->GetXaxis()->SetTitleFont(42);
  hempty_cratioref->GetYaxis()->SetTitleFont(42);
  hempty_cratioref->GetXaxis()->SetLabelFont(42);
  hempty_cratioref->GetYaxis()->SetLabelFont(42);
  hempty_cratioref->GetXaxis()->SetLabelSize(0.04);
  hempty_cratioref->GetYaxis()->SetLabelSize(0.04);  
  hempty_cratioref->Draw();
  gratioref->Draw("psame");
  cratioref->SaveAs(Form("plots/%s/ratioref.pdf",rapi.Data()));

  cout<<endl;

}
Example #26
0
void plotcf(const char* sys="PP", const char* kT="kT1", const char* proj="Out", int mult=2, TString dir = "../train_results_central_dcaptdep", int period=11, int numofpsibins = 6) {

  int seppsi = 0; // indicates if draw in separate psi bins
  int psibins = 0; // indicates if one uses psi binning
  int fname = 1; // indicates if the file name is specified
  int plotinpsibins = 0;
  int rb = 1; // flag to rebinning

  if (mult<2)
    const char* centrality = "central";
  else
    const char* centrality = "semicentral";

  if (period == 11) {

    const int Nruns = 64;
    // const int Nruns = 66;

    int runs[Nruns] = {
      167915, 168115, 168460, 169035, 169238, 169859, 170228  , 167920 // , 168310
      , 168464, 169091, 169411, 169923, 170230, 167985, 168311, 169094, 169415, 170027, 170268, 167987, 168322, 168511, 169138, 169417, 170081, 170269, 167988, 168325, 168512, 169144, 169835, 170155, 170270, 168069,  168341, 168514, 169145, 169837, 170159, 170306// , 168076
      , 168342, 168777,  169148,      169838, 170163, 170308, 168105, 168361, 168826, 169156, 169846, 170193, 170309, 168107 // ,168362
      , 168988,       169160,      169855, 170203, 168108 , 168458,  168992,      169167, 169858, 170204
    };


    // const int Nruns = 62;
    // int runs[Nruns] = {
    //   167915, 168115, 168460, 169035, 169238, 169859, 170228  ,  // 167920 ,
    //   168310, 168464, 169091, 169411, 169923, 170230, 167985, 168311, 169094, 169415, 170027, 170268, 167987, 168322, 168511, 169138, 169417, 170081, 170269, 167988, 168325, 168512, 169144, 169835, 170155, 170270, 168069, // 168341,
    //   168514, 169145, 169837, 170159, 170306, 168076, 168342, 168777, // 169148,
    //   169838, 170163, 170308, 168105, 168361, 168826, 169156, 169846, 170193, 170309, 168107, 168362, // 168988,
    //   // 169160,
    //   169855, 170203, 168108 , 168458,  168992,
    //   169167, 169858, 170204
    // };

  }
  else if (period == 10) {
    const int Nruns = 89;
    int runs[Nruns] = {
      139510, 139507, 139505, 139503, 139465, 139438, 139437, 139360, 139329, 139328, 139314, 139310, 139309, 139173, 139107, 139105, 139038, 139037, 139036, 139029, 139028, 138872, 138871, 138870, 138837, 138732, 138730, 138666, 138662, 138653, 138652, 138638, 138624, 138621, 138583, 138582, 138579, 138578, 138534, 138469, 138442, 138439, 138438, 138396, 138364, 138275, 138225, 138201, 138197, 138192, 138190, 137848, 137844, 137752, 137751, 137724, 137722, 137718, 137704, 137693, 137692, 137691, 137686, 137685, 137639, 137638, 137608, 137595, 137549, 137544, 137541, 137539, 137443, 137441, 137440, 137439, 137434, 137432, 137431, 137430, 137366, 137243, 137236, 137235, 137232, 137231, 137230, 137162, 137161};
  }


  TFile* ifile_[Nruns+1];

  if (plotinpsibins) {
    for (int jf = 0 ; jf < Nruns; ++jf ) {
      ifile_[jf] = new TFile(Form("%s/%d.mergedbinsdir.root",dir.Data(),runs[jf]), "read");
    }
  }
  if (fname)
    ifile_[Nruns] = new TFile(Form("%s",dir.Data()), "read");
  else
    ifile_[Nruns] = new TFile(Form("%s/allrunsmergedbins.root",dir.Data()), "read");


  TH1D* numpp[13][3][Nruns+1];
  TH1D* denpp[13][3][Nruns+1];

  TH1D* numpapoutp[13][3];
  TH1D* numpapoutn[13][3];
  TH1D* numpaplongp[13][3];
  TH1D* numpaplongn[13][3];
  TH1D* numpapsidep[13][3];
  TH1D* numpapsiden[13][3];

  TH1D* denpapoutp[13][3];
  TH1D* denpapoutn[13][3];
  TH1D* denpaplongp[13][3];
  TH1D* denpaplongn[13][3];
  TH1D* denpapsidep[13][3];
  TH1D* denpapsiden[13][3];

  TH1D* numsum;
  TH1D* densum;

	TCanvas *myCan = new TCanvas("asd","asd");
	myCan->Draw();
	myCan->cd();

	TPad *myPad = new TPad("myPad", "The pad",0,0,1,1);
	myPadSetUp(myPad,0.15,0.04,0.04,0.15);
	myPad->Draw();
	myPad->cd();

  TGraph* grnument[13];
  TH2D* hnument = new TH2D("hipsiif","hipsiif",numofpsibins,-0.5,numofpsibins,Nruns,-0.5,Nruns);

  TFile* grofile = new TFile("grofile.root","recreate");

  if (plotinpsibins) {

// _________________________________________________
// // Psi binning.....
// _________________________________________________

// each numerator and denominator from different run
    for (int iPsi = 0; iPsi < numofpsibins; ++iPsi) {

      grnument[iPsi] = new TGraph();

      for (int iif = 0; iif < Nruns; ++iif ) {


        // cout << Form("NumcqinvPPtpcM3Psi%d%s",iPsi,kT) << endl;
        // cout << Form("Numcqinv%stpcM%dPsi%d%s",sys,mult,iPsi,kT) << endl;
        // cout << "iPsi = " << iPsi << endl;
        // // cout << "ikT = " << ikT << endl;
        // cout << "iif = " << iif << endl << endl;

        bool exi = false;

        if (iPsi == 0) {

          if (strcmp(sys,"PAP") != 0) {


            if ( ifile_[iif]->GetListOfKeys()->Contains(Form("Numcqinv%stpcM%dPsi%d%s",sys,mult,iPsi,kT)) ) {
              exi = true;

              numsum = (TH1D*)ifile_[iif]->Get(Form("Numcqinv%stpcM%dPsi%d%s",sys,mult,iPsi,kT));
              densum = (TH1D*)ifile_[iif]->Get(Form("Dencqinv%stpcM%dPsi%d%s",sys,mult,iPsi,kT));

              grnument[iPsi]->SetPoint(grnument[iPsi]->GetN(), iif, numsum->GetEntries());
              hnument->SetBinContent(iPsi+1, iif, numsum->GetEntries());

              if (densum->GetEntries()==0) {
                cout << "iPsi = " << iPsi << endl;
                cout << "iif = " << iif << endl << endl;
              }
            }
          }
          else {
            exi = true;
            numsum = (TH1D*)ifile_[iif]->Get(Form("Num%sPckstarPAPtpcM%dPsi%d%s",proj,mult,iPsi,kT));
            densum = (TH1D*)ifile_[iif]->Get(Form("Den%sPckstarPAPtpcM%dPsi%d%s",proj,mult,iPsi,kT));
            numsumN = (TH1D*)ifile_[iif]->Get(Form("Num%sNckstarPAPtpcM%dPsi%d%s",proj,mult,iPsi,kT));
            densumN = (TH1D*)ifile_[iif]->Get(Form("Den%sNckstarPAPtpcM%dPsi%d%s",proj,mult,iPsi,kT));

            grnument[iPsi]->SetPoint(grnument[iPsi]->GetN(), iif, numsum->GetEntries());
            hnument->SetBinContent(iPsi+1, iif, numsum->GetEntries());

            // numsum->SetBit(TH1::kIsAverage);
            // densum->SetBit(TH1::kIsAverage);
            // numsumN->SetBit(TH1::kIsAverage);
            // densumN->SetBit(TH1::kIsAverage);

          }
          if (exi)
            if (!seppsi) {
              densum->Scale(numsum->GetEntries()/densum->GetEntries());
            }
          if (strcmp(sys,"PAP") == 0) {
            densumN->Scale(numsumN->GetEntries()/densumN->GetEntries());
          }
        }
        else {
          if (strcmp(sys,"PAP") != 0) {
            if ( ifile_[iif]->GetListOfKeys()->Contains(Form("Numcqinv%stpcM%dPsi%d%s",sys,mult,iPsi,kT)) ) {
              exi = true;
              numpp[iPsi][2][iif] = (TH1D*)ifile_[iif]->Get(Form("Numcqinv%stpcM%dPsi%d%s",sys,mult,iPsi,kT));
              denpp[iPsi][2][iif] = (TH1D*)ifile_[iif]->Get(Form("Dencqinv%stpcM%dPsi%d%s",sys,mult,iPsi,kT));

              grnument[iPsi]->SetPoint(grnument[iPsi]->GetN(), iif, numpp[iPsi][2][iif]->GetEntries());
              hnument->SetBinContent(iPsi+1, iif, numpp[iPsi][2][iif]->GetEntries());

              // cout << iPsi << endl;
              // cout << numpp[iPsi][2][iif]->GetEntries() << endl;
              // // cout << denpp[iPsi][2][iif]->GetEntries() << endl;
              // cout << endl;

              if (denpp[iPsi][2][iif]->GetEntries()==0) {
                cout << denpp[iPsi][2][iif]->GetEntries() << endl;
                cout << "iPsi = " << iPsi << endl;
                cout << "iif = " << iif << endl;
              }
            }
          }
          else {
            exi = true;
            numpp[iPsi][2][iif] = (TH1D*)ifile_[iif]->Get(Form("Num%sPckstarPAPtpcM%dPsi%d%s",proj,mult,iPsi,kT));
            denpp[iPsi][2][iif] = (TH1D*)ifile_[iif]->Get(Form("Den%sPckstarPAPtpcM%dPsi%d%s",proj,mult,iPsi,kT));
            numpp[iPsi][0][iif] = (TH1D*)ifile_[iif]->Get(Form("Num%sNckstarPAPtpcM%dPsi%d%s",proj,mult,iPsi,kT));
            denpp[iPsi][0][iif] = (TH1D*)ifile_[iif]->Get(Form("Den%sNckstarPAPtpcM%dPsi%d%s",proj,mult,iPsi,kT));
            // numpp[iPsi][2][iif]->SetBit(TH1::kIsAverage);
            // denpp[iPsi][2][iif]->SetBit(TH1::kIsAverage);
            // numpp[iPsi][0][iif]->SetBit(TH1::kIsAverage);
            // denpp[iPsi][0][iif]->SetBit(TH1::kIsAverage);
            grnument[iPsi]->SetPoint(grnument[iPsi]->GetN(), iif, numpp[iPsi][2][iif]->GetEntries());
            hnument->SetBinContent(iPsi+1, iif, numpp[iPsi][2][iif]->GetEntries());

          }

          if (exi) {
            numsum->Add(numpp[iPsi][2][iif]);
            if (!seppsi)
              denpp[iPsi][2][iif]->Scale(numpp[iPsi][2][iif]->GetEntries()/denpp[iPsi][2][iif]->GetEntries());
            densum->Add(denpp[iPsi][2][iif]);
            if (strcmp(sys,"PAP") == 0) {
              numsumN->Add(numpp[iPsi][0][iif]);
              denpp[iPsi][0][iif]->Scale(numpp[iPsi][0][iif]->GetEntries()/denpp[iPsi][0][iif]->GetEntries());
              densumN->Add(denpp[iPsi][0][iif]);
            }
          }

        }


        // int rb = 2;
        // if (exi) {
        //     cout << "exi" << endl;
        //     numsum->Rebin(rb);
        // }
        // densum->Rebin(rb);
        // numsum->Divide(densum);
        // numsum->SetMarkerColor(1+iPsi);
        // numsum->SetMarkerStyle(20);
        // numsum->SetMarkerSize(1.0);

        // if (iPsi == 0)
        //     numsum->Draw("p");
        // else
        // numsum->Draw("psame");

      }

      if (seppsi) {
        double norm = numsum->GetEntries()/densum->GetEntries();
        cout << iPsi << " " << norm << endl;
        TH1F *hnew = (TH1F*)densum->Clone("hnew");
        hnew->Scale(norm);

        numsum->SetMarkerColor(iPsi+1);
        numsum->SetMarkerStyle(20);
        numsum->SetMarkerSize(1.0);

        int rb = 1;

        numsum->Rebin(rb);
        // densum->Rebin(rb);
        // numsum->Divide(densum);

        hnew->Rebin(rb);
        numsum->Divide(hnew);
        if (iPsi == 0) {
          numsum->DrawCopy("p");
        }
        else {
          numsum->DrawCopy("psame");
        }

        // hnument[iPsi][iif]->Write();

      }
      // cout <<"write ipsi = " << iPsi << endl;
      // grnument[iPsi]->SetName(Form("gr%d",iPsi));
      // grnument[iPsi]->Write();
    }
    // hnument->Write();

    // numpp[6][2]->Draw("p");


    if (!seppsi) {


      if (strcmp(sys,"PAP")==0) {
        numsum->SetBit(TH1::kIsAverage);
        densum->SetBit(TH1::kIsAverage);
        numsumN->SetBit(TH1::kIsAverage);
        densumN->SetBit(TH1::kIsAverage);

        numsum->Add(numsumN);
        densum->Add(densumN);

        numsum->ResetBit(TH1::kIsAverage);
        densum->ResetBit(TH1::kIsAverage);
      }

      numsum->SetMarkerColor(kBlue);
      numsum->SetMarkerStyle(20);
      numsum->SetMarkerSize(1.0);

      int rb = 1;

      numsum->Rebin(rb);
      densum->Rebin(rb);
      numsum->Divide(densum);



      if (psibins)
        numsum->Draw("p");

      // densum->Draw("psame");
    }
  }

// _________________________________________________
// // bez Psi binningu.....
// _________________________________________________


  if (strcmp(sys,"PAP") != 0) {
    numpp[0][2][Nruns] = (TH1D*)ifile_[Nruns]->Get(Form("Numcqinv%stpcM%dPsi%d%s",sys,mult,numofpsibins,kT));
    denpp[0][2][Nruns] = (TH1D*)ifile_[Nruns]->Get(Form("Dencqinv%stpcM%dPsi%d%s",sys,mult,numofpsibins,kT));

    numpp[0][2][Nruns]->SetXTitle("#it{q}_{inv} (GeV/#it{c})");
    numpp[0][2][Nruns]->SetYTitle("C(#it{q}_{inv})");

    // numsum->SetXTitle("#it{q}_{inv} (GeV/#it{c})");
    // numsum->SetYTitle("C(#it{q}_{inv})");

  }
  else {
    numpp[0][2][Nruns] = (TH1D*)ifile_[Nruns]->Get(Form("Num%sPckstarPAPtpcM%dPsi%d%s",proj,mult,numofpsibins,kT));
    denpp[0][2][Nruns] = (TH1D*)ifile_[Nruns]->Get(Form("Den%sPckstarPAPtpcM%dPsi%d%s",proj,mult,numofpsibins,kT));

    numpp[0][0][Nruns] = (TH1D*)ifile_[Nruns]->Get(Form("Num%sNckstarPAPtpcM%dPsi%d%s",proj,mult,numofpsibins,kT));
    denpp[0][0][Nruns] = (TH1D*)ifile_[Nruns]->Get(Form("Den%sNckstarPAPtpcM%dPsi%d%s",proj,mult,numofpsibins,kT));

    numpp[0][2][Nruns]->SetBit(TH1::kIsAverage);
    denpp[0][2][Nruns]->SetBit(TH1::kIsAverage);

    numpp[0][0][Nruns]->SetBit(TH1::kIsAverage);
    denpp[0][0][Nruns]->SetBit(TH1::kIsAverage);

    numpp[0][2][Nruns]->Add(numpp[0][0][Nruns]);
    denpp[0][2][Nruns]->Add(denpp[0][0][Nruns]);

    numpp[0][2][Nruns]->ResetBit(TH1::kIsAverage);
    denpp[0][2][Nruns]->ResetBit(TH1::kIsAverage);

    numpp[0][2][Nruns]->SetXTitle("#it{k*} (GeV/#it{c})");
    numpp[0][2][Nruns]->SetYTitle("C(#it{k*})");

    // numsum->SetXTitle("#it{k*} (GeV/#it{c})");
    // numsum->SetYTitle("C(#it{k*})");

  }

  gStyle->SetOptStat(0);
  numpp[0][2][Nruns]->GetXaxis()->SetTitleSize(0.06);
  numpp[0][2][Nruns]->GetYaxis()->SetTitleSize(0.06);
  numpp[0][2][Nruns]->SetTitle("");

  numpp[0][2][Nruns]->Rebin(rb);
  denpp[0][2][Nruns]->Rebin(rb);

  numpp[0][2][Nruns]->SetMarkerColor(kRed);
  numpp[0][2][Nruns]->SetMarkerStyle(20);
  numpp[0][2][Nruns]->SetMarkerSize(1.0);

  // numsum->GetXaxis()->SetTitleSize(0.06);
  // numsum->GetYaxis()->SetTitleSize(0.06);
  // numsum->SetTitle("");

  // numsum->Rebin(rb);
  // densum->Rebin(rb);


  double norm = denpp[0][2][Nruns]->GetEntries()/numpp[0][2][Nruns]->GetEntries();
  //double norm = calculateNormalizationFactor(numpp[0][2][Nruns],denpp[0][2][Nruns],0.4,0.45 );
  //double norm = calculateNormalizationFactor(numpp[0][2][Nruns],denpp[0][2][Nruns],0.3,0.4 );

  numpp[0][2][Nruns]->Divide(denpp[0][2][Nruns]);
  numpp[0][2][Nruns]->Scale(norm);

  if (strcmp(sys,"PAP") == 0) {
    numpp[0][2][Nruns]->SetMaximum(1.5);
    numpp[0][2][Nruns]->SetMinimum(0.9);
    // numpp[0][2][Nruns]->GetXaxis()->SetRangeUser(0,0.46);
    // numpp[0][2][Nruns]->GetXaxis()->SetRangeUser(0,0.5);

    // numsum->GetXaxis()->SetRangeUser(0,0.6);

    // numsum->SetMaximum(1.058);
    // numsum->SetMinimum(0.912);
    // numsum->SetTitle("");
  }
  else {
    numpp[0][2][Nruns]->SetMaximum(1.5);
    numpp[0][2][Nruns]->SetMinimum(0.9);
    // numsum->SetMaximum(2.2);
    // numsum->SetMinimum(0.5);
    // numpp[0][2][Nruns]->GetXaxis()->SetRangeUser(0,0.26);
    numpp[0][2][Nruns]->GetXaxis()->SetRangeUser(0,0.5);
    // numsum->GetXaxis()->SetRangeUser(0,0.26);
    // numsum->GetXaxis()->SetRangeUser(0,0.3);
  }


// uncomment this to compare
  // if (!psibins)
  numpp[0][2][Nruns]->Draw("p");
  // else
  //   numpp[0][2][Nruns]->Draw("same");






  //numpp[0][2][Nruns]->Write();

  // if (strcmp(sys,"PAP") ==0 ) {
  //   numpp[0][0][Nruns]->Rebin(rb);
  //   denpp[0][0][Nruns]->Rebin(rb);

  //   numpp[0][0][Nruns]->SetMarkerColor(kBlack);
  //   numpp[0][0][Nruns]->SetMarkerStyle(20);
  //   numpp[0][0][Nruns]->SetMarkerSize(1.0);

  //   double norm = denpp[0][0][Nruns]->GetEntries()/numpp[0][0][Nruns]->GetEntries();
  //   numpp[0][0][Nruns]->Divide(denpp[0][0][Nruns]);
  //   numpp[0][0][Nruns]->Scale(norm);
  //   // numpp[0][0][Nruns]->Draw("same");

  //   numsumN->SetMarkerColor(kGreen+2);
  //   numsumN->SetMarkerStyle(20);
  //   numsumN->SetMarkerSize(1.0);

  //   numsumN->Rebin(rb);
  //   densumN->Rebin(rb);
  //   numsumN->Divide(densumN);

  //   // numsumN->Draw("same");
  // }


  // if (psibins) {
  //   TLegend *leg = new TLegend (0.5,0.2,0.7,0.3);
  //   leg->SetFillColor(kWhite);
  //   leg->SetBorderSize(0);
  //   leg->SetTextSize(0.07);
  //   leg->AddEntry(numsum,"w/ #Psi bins","p");
  //   leg->AddEntry(numpp[0][2][Nruns],"w/o EP cut","p");
  //   leg->Draw("same");
  // }


  // TString namef( dir(16,dir.Length()) );
  // cout << namef << endl;

  dir.ReplaceAll("/","_");
  dir.ReplaceAll("..","");
  dir.ReplaceAll(".root","");
  dir.ReplaceAll("_train_results_","");
  dir.ReplaceAll("_central_","");
  dir.ReplaceAll("_semicentral_","");
  dir.ReplaceAll("jun19_","");
  myCan->SaveAs(Form("figs/cf%s%s%s.png",sys,dir.Data(),kT));

  TFile* ofile = new TFile(Form("figs/cf%s%s%s.root",sys,dir.Data(),kT),"recreate");
  numpp[0][2][Nruns]->Write();

  //numsum->Write();


}
Example #27
0
/*
void formatCanvas(TCanvas *c){
  c->Divide(1,2,0.01,0.01);
  c->cd(1);
  c->GetPad(1)->SetLogy();
  c->GetPad(1)->SetPad(0.,0.425,1.,1.);
  c->GetPad(2)->SetPad(0.,0.0,1.,0.425);
  c->GetPad(2)->SetBottomMargin(0.3);
  c->GetPad(2)->SetGridy(1);
}

// divide by bin width
void divideBinWidth(TH1 *h)
{
	h->Sumw2();
	for (int i=0;i<=h->GetNbinsX();i++)
	{
		Float_t val = h->GetBinContent(i);
		Float_t valErr = h->GetBinError(i);
		val/=h->GetBinWidth(i);
		valErr/=h->GetBinWidth(i);
		h->SetBinContent(i,val);
		h->SetBinError(i,valErr);
	}
	h->GetXaxis()->CenterTitle();
	h->GetYaxis()->CenterTitle();
}

void cleanup(TH1F *h)
{
	for (int i=1;i<=h->GetNbinsX();i++)
	{
		double val1 = h->GetBinContent(i);
		double valErr1 = h->GetBinError(i);
		if (valErr1>=val1) {
			h->SetBinContent(i,0);
			h->SetBinError(i,0);
		}
	}   
	
}


// rebin the spectra
TH1F *rebin(TH1F *h, char *histName)
{
	TH1F *hRebin = new TH1F(Form("%s_rebin",h->GetName()),Form("rebin %s",h->GetTitle()),nbins_recrebin,boundaries_recrebin);
	for (int i=1;i<=h->GetNbinsX();i++)
	{
		double val=h->GetBinContent(i);
		double valErr=h->GetBinError(i);
		int binNum = hRebin->FindBin(h->GetBinCenter(i));
		double val1 = hRebin->GetBinContent(binNum);
		double valErr1 = hRebin->GetBinError(binNum);
		hRebin->SetBinContent(binNum,val+val1);
		hRebin->SetBinError(binNum,sqrt(valErr1*valErr1+valErr*valErr));
	}
	cleanup(hRebin);
	hRebin->SetName(histName);
	return hRebin;
}

TH1F *rebin2(TH1F *h, char *histName)
{
	TH1F *hRebin = new TH1F(Form("%s_rebin",h->GetName()),Form("rebin %s",h->GetTitle()),nbins_recrebin_2,boundaries_recrebin_2);
	for (int i=1;i<=h->GetNbinsX();i++)
	{
		double val=h->GetBinContent(i);
		double valErr=h->GetBinError(i);
		int binNum = hRebin->FindBin(h->GetBinCenter(i));
		double val1 = hRebin->GetBinContent(binNum);
		double valErr1 = hRebin->GetBinError(binNum);
		hRebin->SetBinContent(binNum,val+val1);
		hRebin->SetBinError(binNum,sqrt(valErr1*valErr1+valErr*valErr));
	}
	cleanup(hRebin);
	hRebin->SetName(histName);
	return hRebin;
}

void drawText(const char *text, float xp, float yp, int size){
	TLatex *tex = new TLatex(xp,yp,text);
	tex->SetTextFont(63);
	tex->SetTextSize(size);
	tex->SetTextColor(kBlack);
	tex->SetLineWidth(1);
	//tex->SetTextFont(42);
	tex->SetNDC();
	tex->Draw();
}


void putCMSPrel(double x, double y, double size){
	TLatex *tex=0;
	tex = new TLatex(x,y,"CMS Preliminary");
	tex->SetTextSize(size);
	tex->SetLineWidth(2);
	tex->SetNDC();
	tex->Draw();
}

void putCMSSim(double x, double y, double size){
	TLatex *tex=0;
	tex = new TLatex(x,y,"CMS Simulation");
	tex->SetTextSize(size);
	tex->SetLineWidth(2);
	tex->SetNDC();
	tex->Draw();
}


TLegend *myLegend(double x1,double y1,double x2, double y2)
{
	TLegend *leg = new TLegend(x1,y1,x2,y2);
	leg->SetBorderSize(0);
	leg->SetFillStyle(0);
	return leg; 
	
}

*/
void nlo_comp_macro(int radius = 3){

  TH1::SetDefaultSumw2();
  gStyle->SetOptStat(0);
  
  TFile *fPP = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/result-2013-akVs3PF-cent-1-isFineBin-0/pbpb_pp_merged_chmx_pt_isMC_0_Unfo_2013_akVs3PF_cent_1_isFineBin_0.root");
  //TFile *fNLO_err = TFile::Open("fnl4350a_cteq");
  TFile *fNLO_nnpdf = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_nnpdf21-nlo_aspdf_new.root");
  TFile *fNLO_cteq = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_cteq66-nlo_aspdf_all_new.root");
  TFile *fNLO_ct10n = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_ct10n-nlo_aspdf_new.root");
  TFile *fNLO_hera = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/fnl4350a_hera15all-nlo_aspdf_new.root");

  //alright lets get the unfolded data here: remember we need it for eta range -2 to +2 
  //TFile* fPP_unfo_R3 = TFile::Open("pp_2013_2760_abs_eta_2_mc_ak3PF.root");
  TFile* fPP_unfo_R4 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/pp_2013_2760_abs_eta_2_mc_ak4PF.root");
  TFile* fPP_unfo_R5 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/CMSSW_6_0_0/src/pp_2013_2760_abs_eta_2_mc_ak5PF.root");
  //TFile *f_unfold_R2 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/PbPb_pp_unfold_marguerite_jet80_chMaxjtpt_norawptcut_test_65GeVCut_akPu2PF_20150205_test.root");
  TFile *f_unfold_R3 = TFile::Open(Form("Pawan_ntuple_PbPb_pp_calopfpt_ppNoJetidcut_nlobins_R0p%d_without80FakeRemoval_unfold_mcclosure_oppside_trgMC_noSmear_20_eta_20_%dGeVCut_akPF_20150522.root",3,40));
  //TFile *f_unfold_R4 = TFile::Open("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_20/src/Output/PbPb_pp_unfold_marguerite_jet80_chMaxjtpt_norawptcut_test_65GeVCut_akPu4PF_20150205_test.root");

  TH1F* hPP_data_R_3 = (TH1F*)f_unfold_R3->Get("PP_bayesian_unfolded_spectra");
  hPP_data_R_3->Print("base");
  
  hPP_data_R_3 = (TH1F*)hPP_data_R_3->Rebin(nbins_yaxian, "PP_bayesian_unfolded_spectra", boundaries_yaxian);
  divideBinWidth(hPP_data_R_3);
  hPP_data_R_3->Print("base");

  //PP_measured[0] = (TH1F*)f_unfold_R2->Get("PP_measured_unfolded_spectra");
  //PP_binbybin[0] = (TH1F*)f_unfold_R2->Get("PP_binbybin_unfolded_spectra");

  //TH1F* PP_bayesian[1] = (TH1F*)f_unfold_R4->Get("PP_bayesian_unfolded_spectra");
  //PP_measured[1] = (TH1F*)f_unfold_R3->Get("PP_measured_unfolded_spectra");
  //PP_binbybin[1] = (TH1F*)f_unfold_R3->Get("PP_binbybin_unfolded_spectra");

  TFile fout("pp_2760GeV_nlo_histos.root","RECREATE");
  fout.cd();

  TH1F* hPP_nnpdf_NLO = (TH1F*)fNLO_nnpdf->Get(Form("h100%d00",radius-1));
  TH1F* hPP_cteq_NLO = (TH1F*)fNLO_cteq->Get(Form("h100%d00",radius-1));
  TH1F* hPP_ct10n_NLO = (TH1F*)fNLO_ct10n->Get(Form("h100%d00",radius-1));
  TH1F* hPP_hera_NLO = (TH1F*)fNLO_hera->Get(Form("h100%d00",radius-1));

  //TH1F* hPP_data_R_3 = (TH1F*)fPP_unfo_R3->Get("Unfolded_cent1");
  TH1F* hPP_data_R_4 = (TH1F*)fPP_unfo_R4->Get("Unfolded_cent1");
  TH1F* hPP_data_R_5 = (TH1F*)fPP_unfo_R5->Get("Unfolded_cent1");

  hPP_data_R_3->Scale(5.3*1e3);
  hPP_data_R_3->Scale(1./5300e6);
  //hPP_data_R_3->Scale(1./4);
  //divideBinWidth(hPP_data_R_3);

  hPP_data_R_4->Scale(1./5300e6);
  hPP_data_R_4->Scale(1./4);
  divideBinWidth(hPP_data_R_4);

  hPP_data_R_5->Scale(1./5300e6);
  hPP_data_R_5->Scale(1./4);
  divideBinWidth(hPP_data_R_5);

  // NLO histograms without any R# at the end correspond to R=0.3 the standard. others are named accordingly

  TH1F* hPP_nnpdf_NLO_R4 = (TH1F*)fNLO_nnpdf->Get("h100300");
  TH1F* hPP_nnpdf_NLO_R2 = (TH1F*)fNLO_nnpdf->Get("h100100");

  TH1F* hPP_cteq_NLO_R4 = (TH1F*)fNLO_cteq->Get("h100300");
  TH1F* hPP_ct10n_NLO_R4 = (TH1F*)fNLO_ct10n->Get("h100300");
  TH1F* hPP_hera_NLO_R4 = (TH1F*)fNLO_hera->Get("h100300");

  TH1F* hPP_cteq_NLO_R2 = (TH1F*)fNLO_cteq->Get("h100100");
  TH1F* hPP_ct10n_NLO_R2 = (TH1F*)fNLO_ct10n->Get("h100100");
  TH1F* hPP_hera_NLO_R2 = (TH1F*)fNLO_hera->Get("h100100");

  TH1F* hPP_err = (TH1F*)fNLO_cteq->Get("h100203");
  TH1F* hPP_err_R4 = (TH1F*)fNLO_cteq->Get("h100303");
  TH1F* hPP_err_R2 = (TH1F*)fNLO_cteq->Get("h100103");
  
  for(int i = 0;i<hPP_nnpdf_NLO->GetNbinsX();i++){
    
    Float_t valErr = hPP_err->GetBinError(i);
    hPP_nnpdf_NLO->SetBinError(i,valErr);
    hPP_cteq_NLO->SetBinError(i,valErr);
    hPP_hera_NLO->SetBinError(i,valErr);
    hPP_ct10n_NLO->SetBinError(i,valErr);

    Float_t valErr_R4 = hPP_err_R4->GetBinError(i);
    hPP_nnpdf_NLO_R4->SetBinError(i,valErr_R4);
    hPP_cteq_NLO_R4->SetBinError(i,valErr_R4);
    hPP_ct10n_NLO_R4->SetBinError(i,valErr_R4);
    hPP_hera_NLO_R4->SetBinError(i,valErr_R4);

    Float_t valErr_R2 = hPP_err_R2->GetBinError(i);
    hPP_nnpdf_NLO_R2->SetBinError(i,valErr_R2);
    hPP_cteq_NLO_R2->SetBinError(i,valErr_R2);
    hPP_ct10n_NLO_R2->SetBinError(i,valErr_R2);
    hPP_hera_NLO_R2->SetBinError(i,valErr_R2);

  }

  //add the NPC factors 
  char etaWidth[dir][256] = {
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20",
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20",
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20",
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20",
    "n10_eta_p10","n20_eta_p20","n25_eta_n20","n20_eta_n15",
    "n15_eta_n10","n10_eta_n05","n05_eta_p05","p05_eta_p10",
    "p10_eta_p15","p15_eta_p20"
  };
  
  char radius_lable[dir][256] = {
    "R2","R2","R2","R2","R2","R2","R2","R2","R2","R2",
    "R3","R3","R3","R3","R3","R3","R3","R3","R3","R3",
    "R4","R4","R4","R4","R4","R4","R4","R4","R4","R4",
    "R5","R5","R5","R5","R5","R5","R5","R5","R5","R5",
    "R7","R7","R7","R7","R7","R7","R7","R7","R7","R7"
  };
  
  ifstream fin_txt[dir];

  int energy = 2760;
  
  for(int i = 0;i<dir;i++){
    
    //ostringstream filename;
    //filename<<"/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_8_HI_patch2/src/Macros/RAA/nlo_files/input_np_txtfiles/NPC_ak_"<<radius_lable[i]<<etaWidth[i]<<"_energy"<<energy<<".txt";
    fin_txt[i].open(Form("/net/hisrv0001/home/rkunnawa/WORK/RAA/CMSSW_5_3_8_HI_patch2_old/src/Macros/RAA/nlo_files/input_np_txtfiles/NPC_ak_%s_%s_energy%d.txt",radius_lable[i],etaWidth[i],energy));
  }

  //apply the correction factors to the NLO histograms 

  Float_t npc = 0;
  Float_t bin = 0;

  //before applying the corrections, lets get a clone of the uncorrected histogram. 
  TH1F* hPP_nnpdf_NLO_noNPC = (TH1F*)hPP_nnpdf_NLO->Clone("hPP_nnpdf_NLO_noNPC");
  int counter = 0;
  while(1){

    fin_txt[11]>>bin>>npc;
    cout<<bin<<" "<<npc<<endl;
    if(!fin_txt[11].good())break;
    int bin_no = hPP_nnpdf_NLO->FindBin(bin);
    //cout<<"bin no = "<<bin_no<<endl;
    //cout<<"boundaries_pt of bin no"<<boundaries_yaxian_large[bin_no]<<endl;
    cout<<"value before applying = "<<hPP_nnpdf_NLO->GetBinContent(bin_no)<<endl;
    hPP_nnpdf_NLO->SetBinContent(bin_no,npc*hPP_nnpdf_NLO->GetBinContent(bin_no));
    cout<<"value after applying = "<<hPP_nnpdf_NLO->GetBinContent(bin_no)<<endl;
    hPP_cteq_NLO->SetBinContent(bin_no,npc*hPP_cteq_NLO->GetBinContent(bin_no));
    hPP_ct10n_NLO->SetBinContent(bin_no,npc*hPP_ct10n_NLO->GetBinContent(bin_no));
    hPP_hera_NLO->SetBinContent(bin_no,npc*hPP_hera_NLO->GetBinContent(bin_no));

    fin_txt[1]>>bin>>npc;
    if(!fin_txt[1].good())break;
    bin_no = hPP_nnpdf_NLO_R2->FindBin(bin);
    hPP_nnpdf_NLO_R2->SetBinContent(bin_no,npc*hPP_nnpdf_NLO_R2->GetBinContent(bin_no));
    hPP_cteq_NLO_R2->SetBinContent(bin_no,npc*hPP_cteq_NLO_R2->GetBinContent(bin_no));
    hPP_ct10n_NLO_R2->SetBinContent(bin_no,npc*hPP_ct10n_NLO_R2->GetBinContent(bin_no));
    hPP_hera_NLO_R2->SetBinContent(bin_no,npc*hPP_hera_NLO_R2->GetBinContent(bin_no));

    fin_txt[21]>>bin>>npc;
    if(!fin_txt[21].good())break;
    bin_no = hPP_nnpdf_NLO_R4->FindBin(bin);
    hPP_nnpdf_NLO_R4->SetBinContent(bin_no,npc*hPP_nnpdf_NLO_R4->GetBinContent(bin_no));
    hPP_cteq_NLO_R4->SetBinContent(bin_no,npc*hPP_cteq_NLO_R4->GetBinContent(bin_no));
    hPP_ct10n_NLO_R4->SetBinContent(bin_no,npc*hPP_ct10n_NLO_R4->GetBinContent(bin_no));
    hPP_hera_NLO_R4->SetBinContent(bin_no,npc*hPP_hera_NLO_R4->GetBinContent(bin_no));

    counter++;

  }

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

  //get a clone after applying the corrections, 
  TH1F* hPP_nnpdf_NLO_NPC = (TH1F*)hPP_nnpdf_NLO->Clone("hPP_nnpdf_NLO_NPC");

  TH1F* hPP_NPC_ratio = (TH1F*)hPP_nnpdf_NLO_NPC->Clone("hPP_NPC_ratio");
  hPP_NPC_ratio->Divide(hPP_nnpdf_NLO_noNPC);
  /*
  TCanvas *cnpc = new TCanvas("cnpc","",800,600);
  //cnpc->SetLogy();
  hPP_NPC_ratio->SetTitle("NPC 2.76 TeV R=0.3");
  hPP_NPC_ratio->SetXTitle("Jet p_{T} (GeV/c)");
  hPP_NPC_ratio->SetYTitle("NP factors");
  hPP_NPC_ratio->SetAxisRange(0.7,1.3,"Y");
  hPP_NPC_ratio->Draw();
  cnpc->SaveAs("pp_2760_npc_R3.pdf","RECREATE");
  */


  hPP_nnpdf_NLO->SetName("hPP_nnpdf_NLO");
  hPP_cteq_NLO->SetName("hPP_cteq_NLO");
  hPP_ct10n_NLO->SetName("hPP_ct10n_NLO");
  hPP_hera_NLO->SetName("hPP_hera_NLO");

  hPP_nnpdf_NLO_R2->SetName("hPP_nnpdf_NLO_R2");
  hPP_nnpdf_NLO_R2->Print("base");
  hPP_cteq_NLO_R2->SetName("hPP_cteq_NLO_R2");
  hPP_cteq_NLO_R2->Print("base");
  hPP_ct10n_NLO_R2->SetName("hPP_ct10n_NLO_R2");
  hPP_ct10n_NLO_R2->Print("base");
  hPP_hera_NLO_R2->SetName("hPP_hera_NLO_R2");

  hPP_nnpdf_NLO_R4->SetName("hPP_nnpdf_NLO_R4");
  hPP_cteq_NLO_R4->SetName("hPP_cteq_NLO_R4");
  hPP_ct10n_NLO_R4->SetName("hPP_ct10n_NLO_R4");
  hPP_hera_NLO_R4->SetName("hPP_hera_NLO_R4");

  hPP_nnpdf_NLO->Write();
  hPP_cteq_NLO->Write();
  hPP_ct10n_NLO->Write();
  hPP_hera_NLO->Write();
  hPP_nnpdf_NLO_R2->Write();
  hPP_cteq_NLO_R2->Write();
  hPP_ct10n_NLO_R2->Write();
  hPP_hera_NLO_R2->Write();
  hPP_nnpdf_NLO_R4->Write();
  hPP_cteq_NLO_R4->Write();
  hPP_ct10n_NLO_R4->Write();
  hPP_hera_NLO_R4->Write();

  TH1F* hPPrebin = (TH1F*)hPP_data_R_3->Clone("hPPrebin");
  //TH1F* hPPrebin_test = (TH1F*)faditya->Get("Corrected Jet Spectrum Aditya");
  //TH1F* hPPrebin = (TH1F*)hPPrebin_test->Rebin(nbins_yaxian_large,"hPPrebin",boundaries_yaxian_large);
  //TH1F* hPPunfo = (TH1F*)fPP->Get("Unfolded_cent6");
  TH1F* hPPgen = (TH1F*)fPP->Get("hGen_cent1");
  //hPPrebin->Scale(64);//remove the sigma scaling from the previous macros
  //dont need this now since we are taking it from a dedicated macro which gives us diff cross section 
  hPP_data_R_3->Scale(1e9);
  hPP_data_R_4->Scale(1e9);
  hPP_data_R_5->Scale(1e9);

  //hPP_nnpdf_NLO->Scale(1./4);
  //hPP_cteq_NLO->Scale(1./4);
  //hPP_hera_NLO->Scale(1./4);

  hPPrebin->Scale(1e9);
  //hPPrebin->Scale(1./5300e6);
  //hPPrebin->Scale(1./4);
  //divideBinWidth(hPPrebin);
 
  hPPgen->Scale(1./4);
  hPPgen->Scale(1e9);

  fout.Write();

  hPP_nnpdf_NLO = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"nnpdf_pp", boundaries_yaxian);
  hPP_nnpdf_NLO->Print("base");
  hPP_cteq_NLO = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"cteq_pp", boundaries_yaxian);
  hPP_cteq_NLO->Print("base");
  hPP_hera_NLO = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hera_pp", boundaries_yaxian);
  hPP_hera_NLO->Print("base");
  hPP_ct10n_NLO = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"ct10n_pp", boundaries_yaxian);
  hPP_ct10n_NLO->Print("base");


  TH1F* hRatio_nnpdf_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_nnpdf_mc",boundaries_yaxian);
  hRatio_nnpdf_mc->Divide(hPP_nnpdf_NLO);
  
  TH1F* hRatio_cteq_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_cteq_mc",boundaries_yaxian);
  hRatio_cteq_mc->Divide(hPP_cteq_NLO);

  TH1F* hRatio_hera_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_hera_mc",boundaries_yaxian);
  hRatio_hera_mc->Divide(hPP_hera_NLO);

  TH1F* hRatio_ct10n_mc = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_ct10n_mc",boundaries_yaxian);
  hRatio_ct10n_mc->Divide(hPP_ct10n_NLO);

  TH1F* hRatio_nnpdf = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_nnpdf",boundaries_yaxian);
  hRatio_nnpdf->Divide(hPPrebin);

  TH1F* hRatio_cteq = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"hRatio_cteq",boundaries_yaxian);
  hRatio_cteq->Divide(hPPrebin);

  TH1F* hRatio_ct10n = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"hRatio_ct10n",boundaries_yaxian);
  hRatio_ct10n->Divide(hPPrebin);

  TH1F* hRatio_hera = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hRatio_hera",boundaries_yaxian);
  hRatio_hera->Divide(hPPrebin);

  TH1F* hRatio_ppgen = (TH1F*)hPPgen->Rebin(nbins_yaxian,"hRatio_ppgen",boundaries_yaxian);
  hRatio_ppgen->Divide(hPPrebin);

  TH1F* hRatio_nnpdf_R_2_4 = (TH1F*)hPP_nnpdf_NLO_R2->Rebin(nbins_yaxian,"hRatio_nnpdf_R_2_4",boundaries_yaxian);
  hRatio_nnpdf_R_2_4->Divide(hPP_nnpdf_NLO_R4);

  TH1F* hRatio_nnpdf_R_3_4 = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_nnpdf_R_3_4",boundaries_yaxian);
  hRatio_nnpdf_R_3_4->Divide(hPP_nnpdf_NLO_R4);

  TH1F* hRatio_cteq_R_2_4 = (TH1F*)hPP_cteq_NLO_R2->Rebin(nbins_yaxian,"hRatio_cteq_R_2_4",boundaries_yaxian);
  hRatio_cteq_R_2_4->Divide(hPP_cteq_NLO_R4);

  TH1F* hRatio_cteq_R_3_4 = (TH1F*)hPP_cteq_NLO->Rebin(nbins_yaxian,"hRatio_cteq_R_3_4",boundaries_yaxian);
  hRatio_cteq_R_3_4->Divide(hPP_cteq_NLO_R4);

  TH1F* hRatio_ct10n_R_2_4 = (TH1F*)hPP_ct10n_NLO_R2->Rebin(nbins_yaxian,"hRatio_ct10n_R_2_4",boundaries_yaxian);
  hRatio_ct10n_R_2_4->Divide(hPP_ct10n_NLO_R4);

  TH1F* hRatio_ct10n_R_3_4 = (TH1F*)hPP_ct10n_NLO->Rebin(nbins_yaxian,"hRatio_ct10n_R_3_4",boundaries_yaxian);
  hRatio_ct10n_R_3_4->Divide(hPP_ct10n_NLO_R4);

  TH1F* hRatio_hera_R_2_4 = (TH1F*)hPP_hera_NLO_R2->Rebin(nbins_yaxian,"hRatio_hera_R_2_4",boundaries_yaxian);
  hRatio_hera_R_2_4->Divide(hPP_hera_NLO_R4);

  TH1F* hRatio_hera_R_3_4 = (TH1F*)hPP_hera_NLO->Rebin(nbins_yaxian,"hRatio_hera_R_3_4",boundaries_yaxian);
  hRatio_hera_R_3_4->Divide(hPP_hera_NLO_R4);

  TH1F* hRatio_data_nnpdf_R_3 = (TH1F*)hPP_nnpdf_NLO->Rebin(nbins_yaxian,"hRatio_data_nnpdf_R_3",boundaries_yaxian);
  hRatio_data_nnpdf_R_3->Divide(hPP_data_R_3);
  
  TH1F* hRatio_data_nnpdf_R_4 = (TH1F*)hPP_nnpdf_NLO_R4->Rebin(nbins_yaxian,"hRatio_data_nnpdf_R_4",boundaries_yaxian);
  hRatio_data_nnpdf_R_4->Divide(hPP_data_R_4);

  TH1F* hRatio_data_R_3_4 = (TH1F*)hPP_data_R_3->Clone("hRatio_data_R_3_4");
  hRatio_data_R_3_4->Divide(hPP_data_R_4);

  TH1F* hRatio_data_R_3_5 = (TH1F*)hPP_data_R_3->Clone("hRatio_data_R_3_5");
  hRatio_data_R_3_5->Divide(hPP_data_R_5);

  TH1F* hRatio_data_R_4_5 = (TH1F*)hPP_data_R_4->Clone("hRatio_data_R_4_5");
  hRatio_data_R_4_5->Divide(hPP_data_R_5);

  /*
  TCanvas *cnlo_mc = new TCanvas("cnlo_mc","",800,600);
  hRatio_nnpdf_mc->SetMarkerColor(kRed);
  hRatio_nnpdf_mc->SetMarkerStyle(20);
  hRatio_nnpdf_mc->SetXTitle("Jet p_{T} (GeV/c)");
  hRatio_nnpdf_mc->SetYTitle("MC/NLO");
  hRatio_nnpdf_mc->SetTitle(" ");
  hRatio_nnpdf_mc->SetAxisRange(0,1.5,"Y");
  hRatio_nnpdf_mc->Draw();

  hRatio_cteq_mc->SetMarkerColor(kBlue);
  hRatio_cteq_mc->SetMarkerStyle(20);
  hRatio_cteq_mc->Draw("same");

  hRatio_ct10n_mc->SetMarkerColor(9);
  hRatio_ct10n_mc->SetMarkerStyle(20);
  hRatio_ct10n_mc->Draw("same");

  hRatio_hera_mc->SetMarkerColor(kGreen);
  hRatio_hera_mc->SetMarkerStyle(20);
  hRatio_hera_mc->Draw("same");

  TLegend *titlenlomc = myLegend(0.10,0.10,0.30,0.30);
  titlenlomc->AddEntry(hRatio_nnpdf_mc,"nnpdf","pl");
  titlenlomc->AddEntry(hRatio_cteq_mc,"cteq","pl");
  titlenlomc->AddEntry(hRatio_ct10n_mc,"ct10n","pl");
  titlenlomc->AddEntry(hRatio_hera_mc,"hera","pl");
  titlenlomc->SetTextSize(0.04);
  titlenlomc->Draw();

  putCMSSim(0.1,0.92,0.06);
  drawText("pp #sqrt{s}=2.76(TeV)",0.65,0.92,16);
  drawText(Form("anti k_{T} R = 0.%d, NP corrections added to NLO",radius),0.15,0.83,16);

  cnlo_mc->SaveAs(Form("Ratio_mc_with_nlo_with_np_R%d.pdf",radius),"RECREATE");
  */

  TCanvas *c1 = new TCanvas("c1","",800,600);
  formatCanvas(c1);
  c1->cd(1);
  c1->cd(1)->SetLogy();
  hPP_nnpdf_NLO->SetMarkerColor(kRed);
  hPP_nnpdf_NLO->SetMarkerStyle(33);
  hPP_cteq_NLO->SetMarkerColor(kBlue);
  hPP_cteq_NLO->SetMarkerStyle(33);
  hPP_ct10n_NLO->SetMarkerColor(9);//purple
  hPP_ct10n_NLO->SetMarkerStyle(33);
  hPP_hera_NLO->SetMarkerColor(kGreen);
  hPP_hera_NLO->SetMarkerStyle(33);
  hPPrebin->SetMarkerColor(kBlack);
  hPPrebin->SetMarkerStyle(8);
  hPPgen->SetMarkerColor(kOrange);
  hPPgen->SetMarkerStyle(8);
  //hPPgen->SetMarkerColor(kRed);
  //hPPgen->SetMarkerStyle(8);
  
  makeHistTitle(hPP_nnpdf_NLO,"","p_{T} (GeV/c)","#frac{d^{2} #sigma}{d p_{T} d #eta} (pb#frac{GeV}{c})");
  //hPP_nnpdf_NLO->SetYTitle("#frac{d^{2} #sigma}{d p_{T} d #eta} (pb#frac{GeV}{c})");
  //hPP_nnpdf_NLO->SetXTitle("p_{T} (GeV/c)");
  hPP_nnpdf_NLO->SetAxisRange(22,500,"X");
  hPP_nnpdf_NLO->SetTitle(" ");
  hPP_nnpdf_NLO->Draw("p");
  hPP_cteq_NLO->Draw("same p");
  hPP_ct10n_NLO->Draw("same p");
  hPP_hera_NLO->Draw("same p");
  hPPrebin->Draw("same p");
  //hPPgen->Draw("same p");

  TLegend * title = myLegend(0.47, 0.50,0.67, 0.8);
  title->AddEntry(hPP_nnpdf_NLO,"NLO nnpdf","pl");
  title->AddEntry(hPP_cteq_NLO,"NLO cteq","pl");
  title->AddEntry(hPP_ct10n_NLO,"NLO ct10n","pl");
  title->AddEntry(hPP_hera_NLO,"NLO hera","pl");
  //title->AddEntry(hPPgen,"pp MC spectra","pl");
  title->AddEntry(hPPrebin,"pp unfolded 2013 data","pl");
  title->SetTextSize(0.04);
  title->Draw();

  putCMSPrel(0.1,0.92,0.06);
  drawText("pp 2013, #sqrt{s}=2.76(TeV), #int L dt = 5.3 (pb)^{-1}",0.35,0.92,16);
  drawText(Form("anti k_{T} R = 0.3, NP corrections added to NLO",radius),0.35,0.83,16);

  c1->cd(2);
  makeHistTitle(hRatio_nnpdf,"","p_{T} (GeV/c)","NLO / pp data");
  //hRatio_nnpdf->SetYTitle(" X / pp data");
  //hRatio_nnpdf->SetXTitle("p_{T} (GeV/c)");
  hRatio_nnpdf->SetTitle(" ");
  hRatio_nnpdf->SetAxisRange(0.8,2,"Y");
  hRatio_nnpdf->SetMarkerColor(kRed);
  hRatio_nnpdf->SetMarkerStyle(33);
  hRatio_hera->SetMarkerColor(kGreen);
  hRatio_hera->SetMarkerStyle(33);
  hRatio_cteq->SetMarkerColor(kBlue);
  hRatio_cteq->SetMarkerStyle(33);
  hRatio_ct10n->SetMarkerColor(9);
  hRatio_ct10n->SetMarkerStyle(33);
  hRatio_ppgen->SetMarkerColor(kOrange);
  hRatio_ppgen->SetMarkerStyle(33);
  hRatio_nnpdf->Draw("p");
  hRatio_nnpdf->SetAxisRange(22,500,"X");
  hRatio_hera->Draw("same p");
  hRatio_cteq->Draw("same p");
  hRatio_ct10n->Draw("same p");
  //hRatio_ppgen->Draw("same p");

  c1->SaveAs(Form("May22/pp_2760GeV_NLO_NPadded_ak%dPF_spectra.pdf",radius),"RECREATE");

  /*
  //get the information from the ratio per bins - to use to scale down the NLO in 5.02 TeV. 
  ofstream R_nnpdf,R_hera,R_cteq;
  R_nnpdf.open(Form("ratio_nnpdf_vs_pp_data_2760_ak%d.txt",radius));
  R_hera.open(Form("ratio_hera_vs_pp_data_2760_ak%d.txt",radius));
  R_cteq.open(Form("ratio_cteq_vs_pp_data_2760_ak%d.txt",radius)); 
  for(int i = 0;i<hRatio_nnpdf->GetNbinsX();i++){
    R_nnpdf<<i<<"\t"<<hRatio_nnpdf->GetBinContent(i)<<endl;
    R_hera<<i<<"\t"<<hRatio_hera->GetBinContent(i)<<endl;
    R_cteq<<i<<"\t"<<hRatio_cteq->GetBinContent(i)<<endl;
  }
  
  R_nnpdf.close();
  R_hera.close();
  R_cteq.close();

  
  //draw the results for NLO comparison within different radius at the same energy 
  TCanvas *c2 = new TCanvas("c2","",800,600);
  formatCanvas(c2);
  
  c2->cd(1);
  hPP_nnpdf_NLO->SetMarkerStyle(22);
  hPP_nnpdf_NLO->SetMarkerColor(3);
  hPP_nnpdf_NLO->Draw("p");
  hPP_nnpdf_NLO_R2->SetMarkerStyle(22);
  hPP_nnpdf_NLO_R2->SetMarkerColor(2);
  hPP_nnpdf_NLO_R2->Draw("same p");
  hPP_nnpdf_NLO_R4->SetMarkerStyle(22);
  hPP_nnpdf_NLO_R4->SetMarkerColor(4);
  hPP_nnpdf_NLO_R4->Draw("same p");
  hPP_data_R_4->SetMarkerStyle(23);
  hPP_data_R_4->SetMarkerColor(4);
  hPP_data_R_4->Draw("same p");
  hPP_data_R_3->SetMarkerStyle(23);
  hPP_data_R_3->SetMarkerColor(3);
  hPP_data_R_3->Draw("same p");
  hPP_data_R_5->SetMarkerStyle(23);
  hPP_data_R_5->SetMarkerColor(9);
  hPP_data_R_5->Draw("same p");

  TLegend * title2 = myLegend(0.47, 0.50,0.67, 0.8);
  title2->AddEntry(hPP_nnpdf_NLO_R2,"NNPDF21 R=0.2","pl");
  title2->AddEntry(hPP_nnpdf_NLO,"NNPDF21 R=0.3","pl");
  title2->AddEntry(hPP_nnpdf_NLO_R4,"NNPDF21 R=0.4","pl");
  title2->AddEntry(hPP_data_R_3,"Data R=0.3","pl");
  title2->AddEntry(hPP_data_R_4,"Data R=0.4","pl");
  title2->AddEntry(hPP_data_R_5,"Data R=0.5","pl");
  title2->SetTextSize(0.04);
  title2->Draw();

  putCMSPrel(0.1,0.92,0.06);
  drawText("pp 2013, #sqrt{s}=2.76(TeV), #int L dt = 5.3 (pb)^{-1}",0.35,0.92,16);
  drawText(Form("anti k_{T}, Data vs Theory",radius),0.47,0.83,16);

  c2->cd(2);
  hRatio_nnpdf_R_2_4->SetMarkerStyle(29);
  hRatio_nnpdf_R_2_4->SetMarkerColor(2);
  hRatio_nnpdf_R_2_4->SetAxisRange(0.6,1.6,"Y");
  hRatio_nnpdf_R_2_4->SetAxisRange(22,500,"X");
  hRatio_nnpdf_R_2_4->SetTitle(" ");
  hRatio_nnpdf_R_2_4->SetYTitle("Ratios");
  hRatio_nnpdf_R_2_4->SetXTitle("p_{T}(GeV/c)");
  hRatio_nnpdf_R_2_4->Draw("p");
  hRatio_nnpdf_R_3_4->SetMarkerStyle(29);
  hRatio_nnpdf_R_3_4->SetMarkerColor(3);
  hRatio_nnpdf_R_3_4->Draw("same p");
  hRatio_data_nnpdf_R_3->SetMarkerStyle(33);
  hRatio_data_nnpdf_R_3->SetMarkerColor(4);
  hRatio_data_nnpdf_R_3->Draw("same p");
  hRatio_data_nnpdf_R_4->SetMarkerStyle(33);
  hRatio_data_nnpdf_R_4->SetMarkerColor(7);
  hRatio_data_nnpdf_R_4->Draw("same p");
  hRatio_data_R_3_4->SetMarkerStyle(34);
  hRatio_data_R_3_4->SetMarkerColor(6);
  hRatio_data_R_3_4->Draw("same p");
  hRatio_data_R_3_5->SetMarkerStyle(34);
  hRatio_data_R_3_5->SetMarkerColor(7);
  hRatio_data_R_3_5->Draw("same p");
  hRatio_data_R_4_5->SetMarkerStyle(34);
  hRatio_data_R_4_5->SetMarkerColor(8);
  hRatio_data_R_4_5->Draw("same p");

  c2->cd(1);
  TLegend * title3 = myLegend(0.67, 0.40,0.77, 0.8);
  title3->AddEntry(hRatio_nnpdf_R_2_4,"NLO R=0.2/R=0.4","pl");
  title3->AddEntry(hRatio_nnpdf_R_3_4,"NLO R=0.3/R=0.4","pl");
  title3->AddEntry(hRatio_data_nnpdf_R_3,"R=0.3 NNPDF21/Data","pl");
  title3->AddEntry(hRatio_data_nnpdf_R_4,"R=0.4 NNPDF21/Data","pl");
  title3->AddEntry(hRatio_data_R_3_4,"Data R=0.3/R=0.4","pl");
  title3->AddEntry(hRatio_data_R_3_5,"Data R=0.3/R=0.5","pl");
  title3->AddEntry(hRatio_data_R_4_5,"Data R=0.4/R=0.5","pl");
  title3->SetTextSize(0.04);
  title3->Draw();
  
  c2->SaveAs("pp_2760GeV_data_NLO_NPCadded_radius_comparison.pdf","RECREATE");

  fout.Write();
  fout.Close();
  */
  
  /*
  TCanvas *c2 = new TCanvas("c2","",1000,800);
  c2->Divide(2,1);
  c2->cd(1);
  c2->cd(1)->SetLogy();
  hPPunfo->SetTitle("PP 2013 2.76 TeV Merged, Unfolded p_{T} Spectra");
  hPPunfo->SetYTitle("#frac{dN}{N_{MB} d p_{T} d #eta}");
  hPPunfo->GetYaxis()->SetTitleOffset(1.4);
  hPPunfo->SetXTitle("Jet p_{T} GeV/c");
  hPPunfo->GetXaxis()->SetRangeUser(50,500);
  hPPunfo->Draw();
  hPPmeas->GetXaxis()->SetRangeUser(50,500);
  hPPmeas->SetMarkerStyle(22);
  hPPmeas->SetMarkerColor(kBlack);
  hPPmeas->Draw("same");
  TLegend *titl = myLegend(0.54,0.65,0.85,0.9);
  titl->AddEntry(hPPmeas,"PP2013 Meas ak3PF","pl");
  titl->AddEntry(hPPunfo,"PP2013 Unfo Bayesian","pl");
  titl->SetTextSize(0.03);
  titl->Draw();
  drawText("Anti-k_{T}PF R = 0.3",0.43,0.6,22);
  drawText("|#eta|<2, |vz|<15",0.47,0.5,22);
  
  c2->cd(2);
  TH1F* hPPRatio = (TH1F*)hPPmeas->Clone("hPPRatio");
  hPPRatio->Divide(hPPunfo);
  hPPRatio->SetXTitle("Jet p_{T} GeV/c");
  hPPRatio->SetYTitle("Ratio Measured/Unfolded");
  hPPRatio->SetTitle("PP2013 ak3PF merged");
  hPPRatio->GetYaxis()->SetRangeUser(0,2);
  hPPRatio->Draw();
  c2->SaveAs("pp_2013_ak3_merged_unfolded_pt.pdf","RECREATE");
  
  */
  
  /*
  TH1F *hNLO_err = (TH1F*)fNLO->Get("h100203");
  for(int i = 0;i<hNLO_err->GetNbinsX();i++){
    Float_T valErr = hNLO_Err->GetBinError(i);
    hNLO->SetBinError(i,valErr);
  }
  */
  /*
  //h100300 - ak4PF, h100200 - ak3PF
  TH1F* hNLO_2 = (TH1F*)hNLO->Clone("hNLO_2");
  hNLO->Print("base");

  TCanvas *cComp = new TCanvas("cComp","",800,600);
  cComp->Divide(2,1);
  cComp->cd(1);

  cComp->cd(1)->SetLogy();
  hPPrebin->SetMarkerStyle(22);
  hPPrebin->SetMarkerColor(kRed);

  hNLO->SetMarkerStyle(20);
  hNLO->SetMarkerColor(kBlack);
  hNLO->SetTitle("PP 2.76 TeV");
  hNLO->SetYTitle("#sigma pb");
  hNLO->SetXTitle("Jet p_{T} GeV/c");
  hNLO->Draw("pl");

  hPPMCrebin->SetMarkerStyle(21);
  hPPMCrebin->SetMarkerColor(kBlue);

  hPPMCrebin->Draw("same");

  hPPrebin->Draw("same");

  TLegend *title = myLegend(0.34,0.65,0.54,0.75);
  title->AddEntry(hNLO,"NLO nnpdf21","pl");
  title->AddEntry(hPPrebin,"PP ak3PF unfo","pl");
  title->AddEntry(hPPMCrebin,"PP ak3PF MC Gen","pl");
  title->SetTextSize(0.06);
  title->Draw();
  

  cComp->cd(2);
  TH1F *hPP = (TH1F*)hPPrebin->Clone("hPP");
  TH1F* hPPMC_v2 = (TH1F*)hPPMCrebin->Clone("hPPMC_v2");

  hPP->Print("base");
  hPPMC_v2->Print("base");
  
  hPP->Divide(hNLO);
  hPPMC_v2->Divide(hNLO);
  hPP->SetTitle("Ratio of PP ak3PF unfolded and MC Gen to NLO");
  //hPP->SetTitle("Ratio of PP ak4PF measured to NLO");
  hPP->SetYTitle("#frac{#sigma_{PP}}{#sigma_{NLO}}");
  hPP->SetXTitle("Jet p_{T} GeV/c");
  hPP->Draw();
  hPPMC_v2->Draw("same");

  cComp->SaveAs("fastNLO_comparison/ratio_pp_ak3_merged_NLO_nnpdf21nlo.pdf","RECREATE");

  TCanvas c1;
  c1.SetLogy();
  hPPrebin->SetAxisRange(50,500,"X");
  hPPrebin->SetYTitle("#sigma (pb)");
  hPPrebin->SetXTitle("Jet p_{T} GeV/c");
  hPPrebin->SetTitle("PP ak3PF unfolded");
  hPPrebin->Draw();
  c1.SaveAs("fastNLO_comparison/PP_2013_ak3_merged_Unfolded_crosssection.pdf","RECREATE");
  c1.SaveAs("fastNLO_comparison/PP_2013_ak3_merged_Unfolded_crosssection.C","RECREATE");
  
  TCanvas *c3 = new TCanvas("c3","",800,600);
  c3->SetGrid();
  c3->SetLogy();
  //TGraphErrors graph_Expected("./fastNLO_comparison/files/s2760_R0.3fine.tex","%lg %lg");
  //graph_Expected.SetTitle("Non Perturbative corrections (extrapolation from Atlas) s2760;p_{T} GeV/c;#sigma nb");
  //graph_Expected.DrawClone("E3AL");
  

  TFile *fNPC = TFile::Open("fastNLO_comparison/files/npc_extrapolation_ivan.root");
  TH1F* hNPC = (TH1F*)fNPC->Get("hNPC");
  hNPC->Scale(1000);// 1000 for the pb from nb 
  //hNPC->Print("base");
  //TH1F* hNPC_rebin1 = rebin2(hNPC,"hNPC_rebin1");
  //divideBinWidth(hNPC_rebin1);
  hNPC->SetTitle("Non Perturbative corrections (extrapolation from Atlas) s2760");
  hNPC->SetXTitle("p_{T} GeV/c");
  hNPC->SetYTitle("#sigma (pb)");
  hNPC->Draw();
  hPPrebin->Draw("same");

  c3->SaveAs("fastNLO_comparison/NPC_atlas_ak3.pdf","RECREATE");


  TCanvas *c4 = new TCanvas("c4","",800,600);
  c4->SetLogy();
  //TH1F* hNPC_rebin = (TH1F*)hNPC->Clone("hNPC_rebin");
  TH1F* hNPC_rebin = rebin2(hNPC,"hNPC_rebin");
  divideBinWidth(hNPC_rebin);
  hPPrebin_2->SetTitle("PP Cross sections Data and Theory comparisons");
  hPPrebin_2->SetYTitle("#sigma (pb)");
  hPPrebin_2->SetXTitle("p_{T} GeV/c");
  //hNPC_rebin->SetAxisRange(1e4,1e-2,"Y");  
  hPPrebin_2->SetMarkerStyle(23);
  hPPrebin_2->SetMarkerColor(kBlack);
  hPPrebin_2->SetAxisRange(50,450,"X");
  hPPrebin_2->Draw("E");
  //hPPrebin_2->SetAxisRange(50,450,"X");
  hNPC_rebin->SetMarkerStyle(21);
  hNPC_rebin->SetMarkerColor(kRed);
  hNPC_rebin->Draw("same");
  hNLO_2->SetMarkerStyle(25);
  hNLO_2->SetMarkerColor(kBlue);
  hNLO_2->Draw("same");

  TLegend *title2 = myLegend(0.54,0.65,0.85,0.9);
  title2->AddEntry(hNPC_rebin,"Ivan NPC - Atlas R=0.3","pl");
  title2->AddEntry(hPPrebin_2,"PP2013 ak3PF unfolded","pl");
  title2->AddEntry(hNLO_2,"CMS NLO nnpdf21 R=0.3","l");

  title2->SetTextSize(0.04);
  title2->Draw();
  gStyle->SetOptStat(0);
 
  c4->SaveAs("fastNLO_comparison/pp_ak3_nlo_overlay_hist.pdf","RECREATE");

  TCanvas *c6 = new TCanvas("c6","",800,600);
  TH1F* hPPratio = (TH1F*)hPPrebin_2->Clone("hPPratio");

  //add the error bars directly before dividing them and then set that as the error. 
  //FLoat_t delta_PP = 0;
  //Float_t delta_NPC = 0;
  //Float_t delta
  
  hPPratio->Divide(hNPC_rebin);
  hPPratio->SetTitle("Ratio of PP 2013 ak3 unfolded w/ Ivan's NPC Atlas");
  hPPratio->SetYTitle(" ");
  hPPratio->SetXTitle("p_{T} GeV/c");
  hPPratio->Draw();
  c6->SaveAs("pp_ak3_npc_ratio.pdf","RECREATE");

  TCanvas *c5 = new TCanvas("c5","",800,600);
  hNPC->Draw();
  hNPC_rebin->Draw("same");
  c5->SetLogy();
  c5->SaveAs("Ivan_plot_rebin_ak3.pdf","RECREATE");
 
  */


}
void macro_MakeFRClosureTest()
{
  // parameters //////////////////////////////////////////////////////////////
  // luminosity of data
  const float lumi = 10445;

  string inputFilePrefix = "invMassHistos";  // lumi and .root will be added
  //string inputFilePrefix = "test";

  // plot data?
  const bool plotData = true;
  //const bool plotData = false;

  // which closure tests should be plotted?
  bool plotClosureTest[4];
  plotClosureTest[0] = true;  // no corrections
  plotClosureTest[1] = true;  // GSF electrons not passing HEEP
  plotClosureTest[2] = true;  // all above + HEEP-GSF corrected with DY contribuion
  plotClosureTest[3] = true;  // all above + GSF-GSF corrected with W+jet and gamma+jet contribution

  // which histograms should be plotted?
  bool plotHisto[4];
  plotHisto[0] = true;  // EB-EB + EB-EE
  plotHisto[1] = true;  // EB-EB
  plotHisto[2] = true;  // EB-EE
  plotHisto[3] = true;  // EE-EE

  int font = 42;
  ////////////////////////////////////////////////////////////////////////////

  const double yAxisMin = 0.001;
//  const int rebin = 10;
  float massMin = 50;
  float massMax = 2050;
  int nBins = 2000;
  vector<pair<float, float> > binning;
  // VARIABLE BINNING
//  binning.push_back(make_pair(100, 1));
//  binning.push_back(make_pair(500, 10));
//  binning.push_back(make_pair(massMax, 50));
  // CONSTANT BINNING
  binning.push_back(make_pair(massMax, 10));

  vector<float> bins;
  bins.push_back(massMin);
  for (vector<pair<float,float> >::iterator it = binning.begin(); it < binning.end(); ++it) {
    while (bins.back() < it->first)
      bins.push_back(bins.back() + it->second);
  }
  if (bins.back() < massMax)
    bins.push_back(massMax);
  nBins = bins.size() - 1;
  Double_t binArray[nBins + 1];
  for (int i = 0; i <= nBins; ++i)
    binArray[i] = (Double_t)bins.at(i);

  stringstream sStream;
  sStream << "Photon_Run2012A-13Jul2012_06Aug2012+DoublePhotonHighPt_Run2012B-13Jul2012+DoublePhotonHighPt_Run2012C-PromptReco-v1+v2_Cert_190456-202016_8TeV_PromptReco_gct1_35_" << lumi << "pb-1";
  //sStream << lumi << "pb-1";
  TString folderDataHisto = sStream.str().c_str();
  // select histograms dynamically depending on state of correction //////////
  vector<TString> folderHeepGsfHisto;
  folderHeepGsfHisto.push_back(sStream.str().c_str());
  folderHeepGsfHisto.push_back(sStream.str().c_str());
  folderHeepGsfHisto.push_back("combinations");
  folderHeepGsfHisto.push_back("combinations");

  vector<TString> folderGsfGsfHisto;
  folderGsfGsfHisto.push_back(sStream.str().c_str());
  folderGsfGsfHisto.push_back(sStream.str().c_str());
  folderGsfGsfHisto.push_back(sStream.str().c_str());
  folderGsfGsfHisto.push_back("combinations");

  vector<TString> heepGsfHisto;
  heepGsfHisto.push_back("histoHeepGsfMassFR");
  heepGsfHisto.push_back("histoHeepGsfMassNoHeepFR");
  heepGsfHisto.push_back("histoHeepGsfCorr");
  heepGsfHisto.push_back("histoHeepGsfCorr");

  vector<TString> gsfGsfHisto;
  gsfGsfHisto.push_back("histoGsfGsfMassFR");
  gsfGsfHisto.push_back("histoGsfGsfMassNoHeepFR");
  gsfGsfHisto.push_back("histoGsfGsfMassNoHeepFR");
  gsfGsfHisto.push_back("histoGsfGsfCorr");
  ////////////////////////////////////////////////////////////////////////////

  vector<TString> canvasName;
  canvasName.push_back("closureFR");
  canvasName.push_back("closureFRNoHeep");
  canvasName.push_back("closureFRCorrDY");
  canvasName.push_back("closureFRCorrFull");

  vector<TString> canvasTitle;
  canvasTitle.push_back("Fake rate closure test uncorrected");
  canvasTitle.push_back("Fake rate closure test GSF (non HEEP)");
  canvasTitle.push_back("Fake rate closure test DY corrected");
  canvasTitle.push_back("Fake rate closure test fully corrected");

  vector<TString> legendHeepGsf;
  legendHeepGsf.push_back("HEEP-GSF uncorrected");
  legendHeepGsf.push_back("HEEP-GSF(non HEEP)");
  legendHeepGsf.push_back("HEEP-GSF DY corrected");
  legendHeepGsf.push_back("HEEP-GSF DY corrected");

  vector<TString> legendGsfGsf;
  legendGsfGsf.push_back("GSF-GSF uncorrected");
  legendGsfGsf.push_back("GSF-GSF (non HEEP)");
  legendGsfGsf.push_back("GSF-GSF (non HEEP)");
  legendGsfGsf.push_back("GSF-GSF W+jet + \\gamma+jet corrected");

  vector<TString> acroSuffix;
  acroSuffix.push_back("");
  acroSuffix.push_back("BB");
  acroSuffix.push_back("BE");
  acroSuffix.push_back("EE");

  vector<TString> suffix;
  suffix.push_back("");
  suffix.push_back(" EB-EB");
  suffix.push_back(" EB-EE");
  suffix.push_back(" EE-EE");

  sStream.str("");
  sStream << inputFilePrefix << lumi << "pb-1.root";
  TFile input(sStream.str().c_str(), "read");
  input.cd();

  cout << endl << "Input file: " << sStream.str() << endl;

  // to keep the histogram when the file is closed
  TH1::AddDirectory(kFALSE);
  TH1::SetDefaultSumw2(kTRUE);
 
  for (unsigned int j = 0; j < 4; ++j) {
    if (!plotClosureTest[j]) continue;
    for (unsigned int p = 0; p < 4; ++p) {
      if (!plotHisto[p]) continue;
  
      TCanvas *c0 = new TCanvas(canvasName[j] + acroSuffix[p], canvasTitle[j] + suffix[p], 100, 100, 800, 600);
      c0->cd();
      c0->SetBorderMode(0);
      c0->SetFrameBorderMode(0);
      c0->SetFillColor(0);
      c0->SetFrameFillColor(0);
      c0->SetLogy();
      gStyle->SetTitleFont(font);
      gStyle->SetLabelFont(font);
      gStyle->SetOptStat(0);
      gStyle->SetPadTickX(1);
      gStyle->SetPadTickY(1);
  
      // get the histograms 
      input.cd(folderGsfGsfHisto[j]);
      TH1F *histoGsfGsf = (TH1F *)gDirectory->Get(gsfGsfHisto[j] + acroSuffix[p]);
      input.cd(folderHeepGsfHisto[j]);
      TH1F *histoHeepGsf = (TH1F *)gDirectory->Get(heepGsfHisto[j] + acroSuffix[p]);
      input.cd(folderDataHisto);
      TH1F *histoData = (TH1F *)gDirectory->Get("histoHeepHeepMass" + acroSuffix[p]);

      TH1F *histoGsfGsfRebinned = (TH1F *)histoGsfGsf->Rebin(nBins, gsfGsfHisto[j] + "Rebinned" + acroSuffix[p], binArray);
      TH1F *histoHeepGsfRebinned = (TH1F *)histoHeepGsf->Rebin(nBins, heepGsfHisto[j] + "Rebinned" + acroSuffix[p], binArray);
      TH1F *histoDataRebinned = (TH1F *)histoData->Rebin(nBins, "histoHeepHeepMassRebinned" + acroSuffix[p], binArray);
  
      histoGsfGsfRebinned->SetLineColor(4);
      histoGsfGsfRebinned->SetMarkerColor(4);
      histoGsfGsfRebinned->SetMarkerStyle(20);
      histoGsfGsfRebinned->SetTitleFont(font);
      histoHeepGsfRebinned->SetLineColor(2);
      histoHeepGsfRebinned->SetMarkerColor(2);
      histoHeepGsfRebinned->SetMarkerStyle(21);
      histoHeepGsfRebinned->SetTitleFont(font);
      histoHeepGsfRebinned->GetYaxis()->SetTitleFont(font);
      histoHeepGsfRebinned->GetYaxis()->SetLabelFont(font);
      histoHeepGsfRebinned->GetXaxis()->SetLabelFont(font);
      histoDataRebinned->SetLineColor(1);
      histoDataRebinned->SetMarkerColor(1);
      histoDataRebinned->SetMarkerStyle(20);
      histoDataRebinned->SetTitleFont(font);
      histoDataRebinned->GetYaxis()->SetTitleFont(font);
      histoDataRebinned->GetYaxis()->SetLabelFont(font);
      histoDataRebinned->GetXaxis()->SetLabelFont(font);
 
      sStream.str("");
      if (binning.size() > 1)
        sStream << "# of events / bin";
      else
        sStream << "# of events / " << binning.begin()->second << "GeV";

      if (plotData) { 
        histoDataRebinned->SetMinimum(yAxisMin);
        histoDataRebinned->SetTitle(canvasTitle[j] + suffix[p]);
        histoDataRebinned->GetYaxis()->SetTitle(sStream.str().c_str());

        histoDataRebinned->Draw();
        histoHeepGsfRebinned->Draw("sames");
      } else {
        histoHeepGsfRebinned->SetTitle(canvasTitle[j] + suffix[p]);
        histoHeepGsfRebinned->GetYaxis()->SetTitle(sStream.str().c_str());
        histoHeepGsfRebinned->Draw();
      }
      histoGsfGsfRebinned->Draw("sames");
  
      sStream.str("");
      sStream << "#sqrt{s} = 8TeV,  #int L dt = " << lumi << "pb^{-1}";
      TPaveLabel *label0 = new TPaveLabel(0.6, 0.79, 0.9, 0.89, sStream.str().c_str(), "brNDC");
      label0->SetFillColor(0);
      label0->SetFillStyle(0);
      label0->SetBorderSize(0);
      label0->SetTextSize(0.30);
      label0->SetTextFont(font);
      label0->Draw("sames");
      TPaveLabel *label1 = new TPaveLabel(0.7, 0.89, 0.91, 0.98, "CMS preliminary", "brNDC");
      label1->SetFillColor(0);
      label1->SetFillStyle(0);
      label1->SetBorderSize(0);
      label1->SetTextSize(0.40);
      label1->SetTextFont(font);
      label1->Draw("sames");
  
      TLegend *legend = new TLegend(0.38, 0.6, 0.53, 0.9);
      if (!plotData) legend->SetY2(0.8);
      legend->SetTextSize(0.03);
      legend->SetTextFont(font);
      legend->SetBorderSize(0);
      legend->SetFillStyle(0);
      if (plotData) legend->AddEntry(histoDataRebinned, "Data", "lep");
      legend->AddEntry(histoHeepGsfRebinned, legendHeepGsf[j], "lep");
      legend->AddEntry(histoGsfGsfRebinned, legendGsfGsf[j], "lep");
      legend->Draw("sames"); 
    } // end loop over eta ranges
  } // end loop over corrections
  input.Close();
}
Example #29
0
void comparisonJetMCData(string plot,int rebin){
  string tmp;

  string dir="/gpfs/cms/data/2011/Observables/Approval/";
	
  if (isAngularAnalysis){
    mcfile=dir+"MC_zjets"+version;
    back_w=dir+"MC_wjets"+version;
    back_ttbar=dir+"MC_ttbar"+version;
    WW=dir+"MC_diW"+version;
    ZZ=dir+"MC_siZ"+version;
    WZ=dir+"MC_diWZ"+version;
    datafile=dir+"DATA"+version;
    mcfiletau=dir+"MC_zjetstau"+version;
  }
  // List of files

  TFile *dataf = TFile::Open(datafile.c_str()); //data file
  TFile *mcf = TFile::Open(mcfile.c_str()); //MC file
  TFile *mcftau = TFile::Open(mcfiletau.c_str()); //MC file
  TFile *ttbarf = TFile::Open(back_ttbar.c_str()); //MC background file
  TFile *wf = TFile::Open(back_w.c_str());


  TFile *qcd23emf = TFile::Open(qcd23em.c_str());
  TFile *qcd38emf = TFile::Open(qcd38em.c_str());
  TFile *qcd817emf = TFile::Open(qcd817em.c_str());

  TFile *qcd23bcf = TFile::Open(qcd23bc.c_str());
  TFile *qcd38bcf = TFile::Open(qcd38bc.c_str());
  TFile *qcd817bcf = TFile::Open(qcd817bc.c_str());

  TFile *WZf = TFile::Open(WZ.c_str());
  TFile *ZZf = TFile::Open(ZZ.c_str());
  TFile *WWf = TFile::Open(WW.c_str());


  // Canvas
  if (CanvPlot) delete CanvPlot;
  CanvPlot = new TCanvas("CanvPlot","CanvPlot",0,0,800,600);

  // Getting, defining ...
  dataf->cd("validationJEC");
  if (isMu && isAngularAnalysis) dataf->cd("validationJECmu");
	
  TObject * obj;
  gDirectory->GetObject(plot.c_str(),obj);

  TH1 *data;
  TH2F *data2; 
  TH1D *data3; 

  THStack *hs = new THStack("hs","Total MC");


  int flag=-1;
  if ((data = dynamic_cast<TH1F *>(obj)) ){
    flag=1;
    gROOT->Reset();
    gROOT->ForceStyle();
    gStyle->SetPadRightMargin(0.03);
    gPad->SetLogy(1);
    gPad->Modified();
    gPad->Update();
  }
  if ((data2 = dynamic_cast<TH2F *>(obj)) ){
    flag=2;
    gStyle->SetPalette(1);
    gStyle->SetPadRightMargin(0.15);
    gPad->Modified();
  }



  //===================
  // Dirty jobs :)
  if (flag==1){
    CanvPlot->cd();
    TPad *pad1 = new TPad("pad1","pad1",0.01,0.33,0.99,0.99);
    pad1->Draw();
    pad1->cd();
    pad1->SetTopMargin(0.1);
    pad1->SetBottomMargin(0.01);
    pad1->SetRightMargin(0.1);
    pad1->SetFillStyle(0);
    pad1->SetLogy(1);
    TString str=data->GetTitle();
    if (str.Contains("jet") && !str.Contains("zMass") && !str.Contains("Num") && !str.Contains("Eta") && !str.Contains("Phi") && !str.Contains("eld") && !str.Contains("meanPtZVsNjet")) {
      if (!isAngularAnalysis) rebin=1;
    }

    //======================
    // DATA
    Double_t dataint = data->Integral();
    data->SetLineColor(kBlack);
    data->Rebin(rebin);
    if(str.Contains("nJetVtx")) data->GetXaxis()->SetRangeUser(0,10);	
    if(str.Contains("zMass")) data->GetXaxis()->SetRangeUser(70,110);	
    data->SetMinimum(1.);
    data->Sumw2();

    //Canvas style copied from plotsHistsRatio.C
    data->SetLabelSize(0.0);
    data->GetXaxis()->SetTitleSize(0.00);
    data->GetYaxis()->SetLabelSize(0.07);
    data->GetYaxis()->SetTitleSize(0.08);
    data->GetYaxis()->SetTitleOffset(0.76);
    data->SetTitle("");
    gStyle->SetOptStat(0);

    data->GetYaxis()->SetLabelSize(0.06);
    data->GetYaxis()->SetTitleSize(0.06);
    data->GetYaxis()->SetTitleOffset(0.8);

    data->Draw("E1");


    TLegend* legend = new TLegend(0.725,0.27,0.85,0.72);
    legend->SetFillColor(0);
    legend->SetFillStyle(0);
    legend->SetBorderSize(0);
    legend->SetTextSize(0.060);
    legend->AddEntry(data,"data","p");

    // hack to calculate some yields in restricted regions...
    int num1=0, num2=0, num3=0, num4=0, num5=0;
    if(str.Contains("invMass") && !str.Contains("PF")){
      for(int j=1;j<=data->GetNbinsX();j++){
	num1 += data->GetBinContent(j); 		//conto quante Z ci sono tra 60 e 120 GeV
	if(j>10&&j<=50) num2 += data->GetBinContent(j); // ... tra 70 e 110
	if(j>15&&j<=45) num3 += data->GetBinContent(j); // ... tra 75 e 105
      }
      cout << "\n";
      cout << data->GetNbinsX() <<" Number of bins of the invmass histo\n";
      printf("Number of Z in 60-120 %i --- 70-110 %i --- 75-105 %i \n",num1,num2,num3);
      cout << "\n";
    }
    if(str.Contains("zYieldVsjets") && !str.Contains("Vtx")){
      for(int j=1;j<=data->GetNbinsX();j++){
	num1 += data->GetBinContent(j); 		//conto quante Z
	if(j>1) num2 += data->GetBinContent(j); // ... +1,2,3,4... jets
	if(j>2) num3 += data->GetBinContent(j); // ... +2,3,4... jets
	if(j>3) num4 += data->GetBinContent(j); // ..    if(str=="jet_pT"){
	if(j>4) num5 += data->GetBinContent(j); // ... +4... jets
      }
      cout << "\n";
      cout << data->GetNbinsX() <<" Number of bins of the zYieldVsjets histo\n";
      printf("Number of Z+n jet %i --- >1 %i --- >2 %i --- >3 %i --- >4 %i \n",num1,num2,num3,num4,num5);
      cout << "\n";
    }    

    //======================
    // Z + jets signal
    mcf->cd("validationJEC");
    if (isMu) mcf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      mcf->cd("validationJEC/");
      if (isMu) mcf->cd("validationJECmu/");
    }

    TH1F* mc;
    gDirectory->GetObject(plot.c_str(),mc);
    TH1F * hsum;
    if(mc){
      hsum =  (TH1F*) mc->Clone();
      hsum->SetTitle("hsum");
      hsum->SetName("hsum");
      hsum->Reset();

      Double_t mcint = mc->Integral();
      mc->SetFillColor(kRed);
      mc->Sumw2();
      if(lumiweights==0) mc->Scale(dataint/mcint);
		
      // Blocco da propagare negli altri MC
      if(zNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) mc->Scale( dataLumi2011pix / (zNumEvents / zjetsXsect));
	    else mc->Scale( dataLumi2011 / (zNumEvents / zjetsXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) mc->Scale( dataLumi2011Apix / (zNumEvents / zjetsXsect));
	      else mc->Scale( dataLumi2011A / (zNumEvents / zjetsXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) mc->Scale( dataLumi2011Bpix / (zNumEvents / zjetsXsect));
	      else mc->Scale( dataLumi2011B / (zNumEvents / zjetsXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) mc->Scale(zjetsScale);
      }

      // fin qui
      if(lumiweights==1) mc->Scale(1./zwemean);  // perche' i Weights non fanno 1...
      mc->Rebin(rebin);
      if(lumiweights==0) mc->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(mc);
      legend->AddEntry(mc,"Z+jets","f");
    }

    //======================
    // ttbar
    ttbarf->cd("validationJEC");
    if (isMu) ttbarf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      ttbarf->cd("validationJEC/");
      if (isMu) ttbarf->cd("validationJECmu/");
    }

    TH1F* ttbar;
    gDirectory->GetObject(plot.c_str(),ttbar);
	
    if(ttbar){
      ttbar->SetFillColor(kBlue);
      ttbar->Sumw2();

      if(ttNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) ttbar->Scale( dataLumi2011pix / (ttNumEvents / ttbarXsect));
	    else ttbar->Scale( dataLumi2011 / (ttNumEvents / ttbarXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) ttbar->Scale( dataLumi2011Apix / (ttNumEvents / ttbarXsect));
	      else ttbar->Scale( dataLumi2011A / (ttNumEvents / ttbarXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) ttbar->Scale( dataLumi2011Bpix / (ttNumEvents / ttbarXsect));
	      else ttbar->Scale( dataLumi2011B / (ttNumEvents / ttbarXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) ttbar->Scale(ttwemean);
      }
      // fin qui
		
      if(lumiweights==1) ttbar->Scale(1./ttwemean);  // perche' i Weights non fanno 1...
      ttbar->Rebin(rebin);
      if(lumiweights==0) ttbar->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(ttbar);
      if(lumiweights==1)legend->AddEntry(ttbar,"ttbar","f");

      //////////
      //Storing the bckgrounds!
      //////////
      cout<<str<<endl;
      if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(ttbar,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(ttbar,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(ttbar,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(ttbar,"jet_pT4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(ttbar,"jet_Multiplicity");
      if(str=="jet_eta") evaluateAndFillBackgrounds(ttbar,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(ttbar,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(ttbar,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(ttbar,"jet_eta4");
      if(str=="HT") evaluateAndFillBackgrounds(ttbar,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(ttbar,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(ttbar,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(ttbar,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(ttbar,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(ttbar,"PhiStar");
      }
    }

    //======================
    // w+jets
    wf->cd("validationJEC");
    if (isMu) wf->cd("validationJECmu/");
    if (isAngularAnalysis) {
      wf->cd("validationJEC/");
      if (isMu) wf->cd("validationJECmu/");      
    }

    TH1F* w;
    gDirectory->GetObject(plot.c_str(),w);
    if(w){

      w->SetFillColor(kViolet+2);
      w->Sumw2();

      if(wNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) w->Scale( dataLumi2011pix / (wNumEvents / wjetsXsect));
	    else w->Scale( dataLumi2011 / (wNumEvents / wjetsXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) w->Scale( dataLumi2011Apix / (wNumEvents / wjetsXsect));
	      else w->Scale( dataLumi2011A / (wNumEvents / wjetsXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) w->Scale( dataLumi2011Bpix / (wNumEvents / wjetsXsect));
	      else w->Scale( dataLumi2011B / (wNumEvents / wjetsXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) w->Scale(wwemean);
      }
      // fin qui
		
      if(lumiweights==1) w->Scale(1./wwemean);  // perche' i Weights non fanno 1...
      w->Rebin(rebin);
      if(lumiweights==0) w->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(w);
      if(lumiweights==1)legend->AddEntry(w,"W+jets","f");
    }

    //======================
    // wz+jets
    WZf->cd("validationJEC");
    if (isMu) WZf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      WZf->cd("validationJEC/");
      if (isMu) WZf->cd("validationJECmu/");
    }

    TH1F* wz;
    gDirectory->GetObject(plot.c_str(),wz);
    if(wz){
      wz->SetFillColor(kYellow+2);
      wz->Sumw2();

      if(wzEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) wz->Scale( dataLumi2011pix / (wzEvents / WZXsect));
	    else wz->Scale( dataLumi2011 / (wzEvents / WZXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) wz->Scale( dataLumi2011Apix / (wzEvents / WZXsect));
	      else wz->Scale( dataLumi2011A / (wzEvents / WZXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) wz->Scale( dataLumi2011Bpix / (wzEvents / WZXsect));
	      else wz->Scale( dataLumi2011B / (wzEvents / WZXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) wz->Scale(wzjetsScale);
      }
      // fin qui
		
      if(lumiweights==1) wz->Scale(1./wzwemean);  // perche' i Weights non fanno 1...
      wz->Rebin(rebin);
      if(lumiweights==0) wz->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(wz);
      legend->AddEntry(wz,"WZ+jets","f");


      //////////
      //Storing the bckgrounds!
      //////////
     if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(wz,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(wz,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(wz,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(wz,"jet_pT4");
      if(str=="jet_eta") evaluateAndFillBackgrounds(wz,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(wz,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(wz,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(wz,"jet_eta4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(wz,"jet_Multiplicity");
      if(str=="HT") evaluateAndFillBackgrounds(wz,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(wz,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(wz,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(wz,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(wz,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(wz,"PhiStar");
     }
    }
    
		
    //======================
    // zz+jets
    ZZf->cd("validationJEC");
    if (isMu) ZZf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      ZZf->cd("validationJEC/");
      if (isMu) ZZf->cd("validationJECmu/");
    }

    TH1F* zz;
    gDirectory->GetObject(plot.c_str(),zz);
    if(zz){
      zz->SetFillColor(kOrange+2);
      zz->Sumw2();

      if(zzEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) zz->Scale( dataLumi2011pix / (zzEvents / ZZXsect));
	    else zz->Scale( dataLumi2011 / (zzEvents / ZZXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) zz->Scale( dataLumi2011Apix / (zzEvents / ZZXsect));
	      else zz->Scale( dataLumi2011A / (zzEvents / ZZXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) zz->Scale( dataLumi2011Bpix / (zzEvents / ZZXsect));
	      else zz->Scale( dataLumi2011B / (zzEvents / ZZXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) zz->Scale(zzjetsScale);
      }
      // fin qui
		
      if(lumiweights==1) zz->Scale(1./zzwemean);  // perche' i Weights non fanno 1...
      zz->Rebin(rebin);
      if(lumiweights==0) zz->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(zz);
      legend->AddEntry(zz,"ZZ+jets","f");

      //////////
      //Storing the bckgrounds!
      //////////
     if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(zz,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(zz,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(zz,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(zz,"jet_pT4");
      if(str=="jet_eta") evaluateAndFillBackgrounds(zz,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(zz,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(zz,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(zz,"jet_eta4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(zz,"jet_Multiplicity");
      if(str=="HT") evaluateAndFillBackgrounds(zz,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(zz,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(zz,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(zz,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(zz,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(zz,"PhiStar");
     }  
    }
    
    //======================
    // ww+jets
    WWf->cd("validationJEC");
    if (isMu) WWf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      WWf->cd("validationJEC/");
      if (isMu) WWf->cd("validationJECmu/");
    }

    TH1F* ww;
    gDirectory->GetObject(plot.c_str(),ww);
    if(ww){
      ww->SetFillColor(kBlack);
      ww->Sumw2();

      if(wwEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) ww->Scale( dataLumi2011pix / (wwEvents / WWXsect));
	    else ww->Scale( dataLumi2011 / (wwEvents / WWXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) ww->Scale( dataLumi2011Apix / (wwEvents / WWXsect));
	      else ww->Scale( dataLumi2011A / (wwEvents / WWXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) ww->Scale( dataLumi2011Bpix / (wwEvents / WWXsect));
	      else ww->Scale( dataLumi2011B / (wwEvents / WWXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) ww->Scale(wwjetsScale);
      }
      // fin qui
		
      if(lumiweights==1) ww->Scale(1./wwwemean);  // perche' i Weights non fanno 1...
      ww->Rebin(rebin);
      if(lumiweights==0) ww->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      hsum->Add(ww);
      legend->AddEntry(ww,"WW+jets","f");

      //////////
      //Storing the bckgrounds!
      //////////
     if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(ww,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(ww,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(ww,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(ww,"jet_pT4");
      if(str=="jet_eta") evaluateAndFillBackgrounds(ww,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(ww,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(ww,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(ww,"jet_eta4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(ww,"jet_Multiplicity");
      if(str=="HT") evaluateAndFillBackgrounds(ww,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(ww,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(ww,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(ww,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(ww,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(ww,"PhiStar");
     }
    }

    /// Tau 

   //======================

    mcftau->cd("validationJEC");
    if (isMu) mcftau->cd("validationJECmu/");

    if (isAngularAnalysis) {
      mcftau->cd("validationJEC/");
      if (isMu) mcftau->cd("validationJECmu/");
    }

    TH1F* tau;
    gDirectory->GetObject(plot.c_str(),tau);
    if(tau){
      tau->SetFillColor(kGreen);
      tau->Sumw2();

      if(zNumEvents>0.){
	if(lumiweights==1) {
	  if (WholeStat){
	    if (lumiPixel) tau->Scale( dataLumi2011pix / (zNumEvents / zjetsXsect));
	    else tau->Scale( dataLumi2011 / (zNumEvents / zjetsXsect));
	  }
	  else{
	    if (RunA){
	      if (lumiPixel) tau->Scale( dataLumi2011Apix / (zNumEvents / zjetsXsect));
	      else tau->Scale( dataLumi2011A / (zNumEvents / zjetsXsect));
	    }
	    if (!RunA){
	      if (lumiPixel) tau->Scale( dataLumi2011Bpix / (zNumEvents / zjetsXsect));
	      else tau->Scale( dataLumi2011B / (zNumEvents / zjetsXsect));
	    }
	  }
	}
      }
      else {
	if(lumiweights==1) tau->Scale(zjetsScale);
      }
      // fin qui
		
      if(lumiweights==1) tau->Scale(1./zwemean);  // perche' i Weights non fanno 1...
      tau->Rebin(rebin);
      if(lumiweights==0) tau->Draw("HISTO SAMES");
      hsum->Rebin(rebin);
      tau->Scale(1./1000.); //aaaaaaa
      hsum->Add(tau);
      legend->AddEntry(tau,"#tau#tau+jets","f");

      //////////
      //Storing the bckgrounds!
      //////////
     if (isAngularAnalysis){
      if(str=="jet_pT") evaluateAndFillBackgrounds(tau,"jet_pT");
      if(str=="jet_pT2") evaluateAndFillBackgrounds(tau,"jet_pT2");
      if(str=="jet_pT3") evaluateAndFillBackgrounds(tau,"jet_pT3");
      if(str=="jet_pT4") evaluateAndFillBackgrounds(tau,"jet_pT4");
      if(str=="jet_eta") evaluateAndFillBackgrounds(tau,"jet_eta");
      if(str=="jet_eta2") evaluateAndFillBackgrounds(tau,"jet_eta2");
      if(str=="jet_eta3") evaluateAndFillBackgrounds(tau,"jet_eta3");
      if(str=="jet_eta4") evaluateAndFillBackgrounds(tau,"jet_eta4");
      if(str=="Jet_multi") evaluateAndFillBackgrounds(tau,"jet_Multiplicity");
      if(str=="HT") evaluateAndFillBackgrounds(tau,"HT");
      if(str=="HT_1j") evaluateAndFillBackgrounds(tau,"HT1");
      if(str=="HT_2j") evaluateAndFillBackgrounds(tau,"HT2");
      if(str=="HT_3j") evaluateAndFillBackgrounds(tau,"HT3");
      if(str=="HT_4j") evaluateAndFillBackgrounds(tau,"HT4");
      if(str=="Phi_star") evaluateAndFillBackgrounds(tau,"PhiStar");
     }
    }


    /////////
    // Print the bkg contributions
    ////////

    for(int j=0;j<bckg_leadingJetPt.size();j++){      
      cout<<bckg_leadingJetPt[j]<<endl;
    }	

    //======================
    // QCD EM enriched
    qcd23emf->cd("validationJEC");
    TH1F* qcd23emp;
    gDirectory->GetObject(plot.c_str(),qcd23emp);

    if(qcd23emp){
      TH1D * qcdTotEM =  (TH1D*) qcd23emp->Clone(); 
      qcdTotEM->SetTitle("qcd em");
      qcdTotEM->SetName("qcd em");
      qcdTotEM->Reset();
      qcdTotEM->Rebin(rebin);

      qcd38emf->cd("validationJEC");
      TH1F* qcd38emp;
      gDirectory->GetObject(plot.c_str(),qcd38emp);


      qcd817emf->cd("validationJEC");
      TH1F* qcd817emp;
      gDirectory->GetObject(plot.c_str(),qcd817emp);

      qcd23emp->Rebin(rebin);
      qcd23emp->Sumw2();
      qcd23emp->Scale(qcd23emScale); 
      qcd38emp->Rebin(rebin);
      qcd38emp->Sumw2();
      qcd38emp->Scale(qcd38emScale); 
      qcd817emp->Rebin(rebin);
      qcd817emp->Sumw2();
      qcd817emp->Scale(qcd817emScale); 

      qcdTotEM->SetFillColor(kOrange+1);
      qcdTotEM->Add(qcd23emp);
      qcdTotEM->Add(qcd38emp);
      qcdTotEM->Add(qcd817emp);

      hsum->Add(qcdTotEM);

      //if(lumiweights==1)legend->AddEntry(qcdTotEM,"QCD em","f");
    }

    //======================
    // QCD bc
    qcd23bcf->cd("validationJEC");
    TH1F* qcd23bcp;
    TH1D * qcdTotBC;
    bool  qcdbcempty=true;
    gDirectory->GetObject(plot.c_str(),qcd23bcp);

    if(qcd23bcp){
      qcdTotBC =  (TH1D*) qcd23bcp->Clone(); 
      qcdTotBC->SetTitle("qcd bc");
      qcdTotBC->SetName("qcd bc");
      qcdTotBC->Reset();
      qcdTotBC->Rebin(rebin);

      qcd38bcf->cd("validationJEC");
      TH1F* qcd38bcp;
      gDirectory->GetObject(plot.c_str(),qcd38bcp);

      qcd817bcf->cd("validationJEC");
      TH1F* qcd817bcp;
      gDirectory->GetObject(plot.c_str(),qcd817bcp);

      qcd23bcp->Rebin(rebin);
      qcd23bcp->Sumw2();
      qcd23bcp->Scale(qcd23bcScale); 
      qcd38bcp->Rebin(rebin);
      qcd38bcp->Sumw2();
      qcd38bcp->Scale(qcd38bcScale); 
      qcd817bcp->Rebin(rebin);
      qcd817bcp->Sumw2();
      qcd817bcp->Scale(qcd817bcScale); 

      qcdTotBC->SetFillColor(kGreen+2);
      qcdTotBC->Add(qcd23bcp);
      qcdTotBC->Add(qcd38bcp);
      qcdTotBC->Add(qcd817bcp);

      hsum->Add(qcdTotBC);
      if (qcdTotBC->GetEntries()>0) qcdbcempty=false; 

      //if(lumiweights==1)legend->AddEntry(qcdTotBC,"QCD bc","f");
    }

    //======================
    // Add here other backgrounds


    //======================
    // Stacked Histogram
    //if(qcd23em) 	hs->Add(qcdTotEM);
    if(!qcdbcempty) 	hs->Add(qcdTotBC);
    if(w)  	        hs->Add(w);
    if (ww)         hs->Add(ww);
    if(tau)		hs->Add(tau); //Z+Jets
    if (zz)         hs->Add(zz);
    if (wz)         hs->Add(wz);
    if (ttbar)	hs->Add(ttbar);
    if(mc)		hs->Add(mc); //Z+Jets

    // per avere le statistiche
    if(lumiweights==1) hsum->Draw("HISTO SAME");


    //======================
    // Setting the stats
    //pad1->Update(); // altrimenti non becchi la stat
    
    //TPaveStats *r2;
    //if(lumiweights==0) r2 = (TPaveStats*)mc->FindObject("stats");
    //if(lumiweights==1) r2 = (TPaveStats*)hsum->FindObject("stats");
    //r2->SetY1NDC(0.875);     //Uncomment if you wonna add your statistics in the top right corner
    //r2->SetY2NDC(0.75); 
    //r2->SetTextColor(kRed);
		
    if(lumiweights==1) hs->Draw("HISTO SAME");
    gPad->RedrawAxis();
    data->Draw("E1 SAME");
    //r2->Draw(); //here to reactivate the stats
    legend->Draw();
    TLegend* lumi = new TLegend(0.45,0.3,0.75,0.2);
    lumi->SetFillColor(0);
    lumi->SetFillStyle(0);
    lumi->SetBorderSize(0);
    //lumi->AddEntry((TObject*)0,"#int L dt =4.9 1/fb","");
    lumi->Draw();
    string channel;
    if (isMu) channel="Z#rightarrow#mu#mu";
    if (!isMu) channel="Z#rightarrow ee";
    TLatex *latexLabel=CMSPrel(4.890,channel,0.55,0.85); // make fancy label
    latexLabel->Draw("same");

    CanvPlot->Update();

	


    //===============//
    // RATIO DATA MC //
    //===============//
    CanvPlot->cd();
    TPad *pad2 = new TPad("pad2","pad2",0.01,0.01,0.99,0.32);
    pad2->Draw();
    pad2->cd();
    pad2->SetTopMargin(0.01);
    pad2->SetBottomMargin(0.3);
    pad2->SetRightMargin(0.1);
    pad2->SetFillStyle(0);

    TH1D * ratio =  (TH1D*) data->Clone();
    ratio->SetTitle("");
    ratio->SetName("ratio");
    ratio->Reset();

    ratio->Sumw2();
    //data->Sumw2();
    hsum->Sumw2(); // FIXME controlla che sia corretto questo... 
    ratio->SetMarkerSize(.5);
    ratio->SetLineColor(kBlack);
    ratio->SetMarkerColor(kBlack);
    //gStyle->SetOptStat("m");
    TH1F* sumMC;

    hs->Draw("nostack"); 
 
   sumMC=(TH1F*) hs->GetHistogram();
    cout<<sumMC->GetEntries()<<endl;
    ratio->Divide(data,hsum,1.,1.);
    ratio->GetYaxis()->SetRangeUser(0.5,1.5);
    ratio->SetMarkerSize(0.8);
    //pad2->SetTopMargin(1);

   //Canvas style copied from plotsHistsRatio.C
    ratio->GetYaxis()->SetNdivisions(5);
    ratio->GetXaxis()->SetTitleSize(0.14);
    ratio->GetXaxis()->SetLabelSize(0.14);
    ratio->GetYaxis()->SetLabelSize(0.11);
    ratio->GetYaxis()->SetTitleSize(0.11);
    ratio->GetYaxis()->SetTitleOffset(0.43);
    ratio->GetYaxis()->SetTitle("ratio data/MC");   

    ratio->Draw("E1");
		
    TLine *OLine = new TLine(ratio->GetXaxis()->GetXmin(),1.,ratio->GetXaxis()->GetXmax(),1.);
    OLine->SetLineColor(kBlack);
    OLine->SetLineStyle(2);
    OLine->Draw();
 
    TLegend* label = new TLegend(0.60,0.9,0.50,0.95);
    label->SetFillColor(0);
    label->SetFillStyle(0);
    label->SetBorderSize(0);
    //horrible mess
    double binContent = 0;
    double binSum = 0;
    double weightSum = 0;
    double binError = 1;
    double totalbins = ratio->GetSize() -2;
    for(unsigned int bin=1;bin<=totalbins;bin++){
      binContent = ratio->GetBinContent(bin);
      binError = ratio->GetBinError(bin);
      if(binError!=0){
	binSum += binContent/binError;
	weightSum += 1./binError;
      }
    }
    double ymean = binSum / weightSum;
    //double ymean = ratio->GetMean(2);
    stringstream sYmean;
    sYmean << ymean;
    string labeltext=sYmean.str()+" mean Y";
    //label->AddEntry((TObject*)0,labeltext.c_str(),""); // mean on Y
    //label->Draw();
		
    //TPaveStats *r3 = (TPaveStats*)ratio->FindObject("stats");
    //r3->SetX1NDC(0.01);
    //r3->SetX2NDC(0.10); 
    //r3->SetY1NDC(0.20);
    //r3->SetY2NDC(0.50); 
    //gStyle->SetOptStat("mr");
    //r3->SetTextColor(kWhite);
    //r3->SetLineColor(kWhite);
    //r3->Draw();
    CanvPlot->Update();

    tmp=plotpath+plot+".png";
    CanvPlot->Print(tmp.c_str());

  }
  else if (flag==2){
    //CanvPlot.Divide(2,1);
    //CanvPlot.cd(1);

    // data
    dataf->cd("validationJEC");
    if (isMu && isAngularAnalysis) dataf->cd("validationJECmu");

    gDirectory->GetObject(plot.c_str(),data2);
    data2->Draw("COLZ");

    gPad->Update(); // altrimenti non becchi la stat
    TPaveStats *r1 = (TPaveStats*)data2->FindObject("stats");
    //r1->SetX1NDC(0.70); Uncomment if you wonna draw your stat in the top right corner
    //r1->SetX2NDC(0.85); 
    //r1->Draw();
    CanvPlot->Update();

    tmp=plotpath+plot+"data.png";
    CanvPlot->Print(tmp.c_str());


    //CanvPlot.cd(2);
    // montecarlo
    mcf->cd("validationJEC");
    if (isMu) mcf->cd("validationJECmu/");

    if (isAngularAnalysis) {
      mcf->cd("validationJEC/");
      if (isMu) mcf->cd("validationJECmu/");
    }

    gDirectory->GetObject(plot.c_str(),data2);

    data2->SetMinimum(1);
    data2->Draw("COLZ");

    gPad->Update(); // altrimenti non becchi la stat
    //TPaveStats *r2 = (TPaveStats*)data2->FindObject("stats");
    //r2->SetX1NDC(0.70);
    //r2->SetX2NDC(0.85); 
    //r2->Draw();
    CanvPlot->Update();

    tmp=plotpath+plot+"mc.png";
    CanvPlot->Print(tmp.c_str());
  }
  //	else { cout << "You're getting an exception! Most likely there's no histogram here... \n"; }

  delete data;
  delete data2;
  delete hs;
  //delete CanvPlot;

  dataf->Close();
  mcf->Close();
  ttbarf->Close();
  wf->Close();
  qcd23emf->Close();
  qcd38emf->Close();
  qcd817emf->Close();
  qcd23bcf->Close();
  qcd38bcf->Close();
  qcd817bcf->Close();
  WZf->Close();
  ZZf->Close();
  
  if (isAngularAnalysis){
    if (bckg_leadingJetPt.size()>0 && bckg_2leadingJetPt.size()>0 && bckg_3leadingJetPt.size()>0 && bckg_4leadingJetPt.size()>0  && bckg_JetMultiplicity.size()>0 && bckg_HT.size()>0 && bckg_leadingJetEta.size()>0 && bckg_PhiStar.size()>0 && cold){
      fzj->cd();
      treeBKG_->Fill();
      treeBKG_->Write();
      TH1F *leadhisto=new TH1F("leadhisto","leading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size());
      TH1F *leadhisto2=new TH1F("leadhisto2","subleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size());
      TH1F *leadhisto3=new TH1F("leadhisto3","subsubleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size());
      TH1F *leadhisto4=new TH1F("leadhisto4","subsubsubleading jet background contribution",bckg_leadingJetPt.size(),0,bckg_leadingJetPt.size());
      TH1F *multiphisto=new TH1F("multiphisto","jet multiplicity background contribution",bckg_JetMultiplicity.size(),0,bckg_JetMultiplicity.size());

      TH1F *HT=new TH1F("HT","HT background contribution",bckg_HT.size(),0,bckg_HT.size());
      TH1F *HT1=new TH1F("HT1","HT background contribution when >= 1 jet",bckg_HT1.size(),0,bckg_HT1.size());
      TH1F *HT2=new TH1F("HT2","HT background contribution when >= 2 jets",bckg_HT2.size(),0,bckg_HT2.size());
      TH1F *HT3=new TH1F("HT3","HT background contribution when >= 3 jets",bckg_HT3.size(),0,bckg_HT3.size());
      TH1F *HT4=new TH1F("HT4","HT background contribution when >= 4 jets",bckg_HT4.size(),0,bckg_HT4.size());

      TH1F *leadhistoeta=new TH1F("leadhistoeta","leading jet background contribution",bckg_leadingJetEta.size(),0,bckg_leadingJetEta.size());
      TH1F *leadhistoeta2=new TH1F("leadhistoeta2","subleading jet background contribution",bckg_leadingJetEta.size(),0,bckg_leadingJetEta.size());
      TH1F *leadhistoeta3=new TH1F("leadhistoeta3","subsubleading jet background contribution",bckg_leadingJetEta.size(),0,bckg_leadingJetEta.size());
      TH1F *leadhistoeta4=new TH1F("leadhistoeta4","subsubsubleading jet background contribution",bckg_leadingJetEta.size(),0,bckg_leadingJetEta.size());

      TH1F *PhiStar=new TH1F("PhiStar","PhiStar background contribution",bckg_PhiStar.size(),0,bckg_PhiStar.size());

      for (int i=0; i< bckg_leadingJetPt.size(); i++){
	leadhisto->Fill(i,bckg_leadingJetPt[i]);
	leadhisto2->Fill(i,bckg_2leadingJetPt[i]);
	leadhisto3->Fill(i,bckg_3leadingJetPt[i]);
	leadhisto4->Fill(i,bckg_4leadingJetPt[i]);
      }
      leadhisto->Write();
      leadhisto2->Write();
      leadhisto3->Write();
      leadhisto4->Write();

      for (int i=0; i< bckg_leadingJetEta.size(); i++){
	leadhistoeta->Fill(i,bckg_leadingJetEta[i]);
	leadhistoeta2->Fill(i,bckg_2leadingJetEta[i]);
	leadhistoeta3->Fill(i,bckg_3leadingJetEta[i]);
	leadhistoeta4->Fill(i,bckg_4leadingJetEta[i]);
      }
      leadhistoeta->Write();
      leadhistoeta2->Write();
      leadhistoeta3->Write();
      leadhistoeta4->Write();
      //fzj->Close();

      for (int i=0; i< bckg_JetMultiplicity.size(); i++){
	multiphisto->Fill(i,bckg_JetMultiplicity[i]);
      }
      multiphisto->Write();
      
      ///////////////

      for (int i=0; i< bckg_HT.size(); i++){
	HT->Fill(i,bckg_HT[i]);
      }
      HT->Write();
      
      for (int i=0; i< bckg_HT1.size(); i++){
	HT1->Fill(i,bckg_HT1[i]);
      }
      HT1->Write();
      
      for (int i=0; i< bckg_HT2.size(); i++){
	HT2->Fill(i,bckg_HT2[i]);
      }
      HT2->Write();
      
      for (int i=0; i< bckg_HT3.size(); i++){
	HT3->Fill(i,bckg_HT3[i]);
      }
      HT3->Write();
      
      for (int i=0; i< bckg_HT4.size(); i++){
	HT4->Fill(i,bckg_HT4[i]);
      }
      HT4->Write();

      //Phi star
      for (int i=0; i< bckg_PhiStar.size(); i++){
	PhiStar->Fill(i,bckg_PhiStar[i]);
      }
      PhiStar->Write();

    cold=false;
    }
  }
  return;
}
Example #30
0
void make_overlay()
{
  float lumi=1000.;
  vector <string > namelist;
  vector <string > plotlist;
  vector <TFile* > data;
  vector <TFile* > filelist;
  vector<float> nEvtTot;
  vector<float> McXsec;
  vector<float> DataLumi;
  //file 0-3 are the files to fit
  
  filelist.push_back(TFile::Open("/cms/data24/clseitz/MC_4_2_4/TTbarJets_pileup/TTbarJets_LeptonANA_full_e25_met30_b12.root"));
  namelist.push_back("TTbarJEts");
  //nEvtTot.push_back(216095.0);
  nEvtTot.push_back(3701936.0);
McXsec.push_back(157);
  DataLumi.push_back(lumi);
  
  filelist.push_back(TFile::Open("/cms/data24/clseitz/MC_4_2_4/Wprime2/Wp1000_CMS_LeptonANA_e25_met30_b12.root"));
  namelist.push_back("Wp1000");
  nEvtTot.push_back(99995.0);
  McXsec.push_back(0.72);
  DataLumi.push_back(lumi);
  filelist.push_back(TFile::Open("/cms/data24/clseitz/MC_4_2_4/Wprime2/Wp600_CMS_LeptonANA_e25_met30_b12.root"));
  namelist.push_back("Wp600");
  nEvtTot.push_back(99987.0);
  McXsec.push_back(8.0);
  DataLumi.push_back(lumi);
  //filelist.push_back(TFile::Open("/cms/data24/clseitz/MC_4_2_4/Sbottom/Sbottom750_neutralino150_LeptonAna_e25_met30_b12.root"));

filelist.push_back(TFile::Open("/home/clseitz/MyCMS/CMSSW_4_2_4/src/TopBSM/TopXana/submit/test.root"));
  namelist.push_back("Sbottom");
  nEvtTot.push_back(7800.0);
  McXsec.push_back(8.0);
  DataLumi.push_back(lumi);
  filelist.push_back(TFile::Open("/cms/data21/clseitz/CMS_leptons/Electrons/NewCode4/Electrons_full_900_emu_met50_b1.root"));
  namelist.push_back("electron");
  nEvtTot.push_back(1.0);
  McXsec.push_back(1.0);
  DataLumi.push_back(1.0);
  //plotlist.push_back("Event/SumptSig4HighestPlus");
  //plotlist.push_back("Event/SumptSig4SecondHighestPlus");
  //plotlist.push_back("Event/TransMassLepMET4JetPlus");
  //plotlist.push_back("Event/TransMassLepMET4SecondJetPlus");
  //plotlist.push_back("Event/SumptSig4HighestMinus");
  //plotlist.push_back("Event/SumptSig4SecondHighestMinus");
  //plotlist.push_back("Event/TransMassLepMET4JetMinus");
  //plotlist.push_back("Event/TransMassLepMET4SecondJetMinus");
  
  plotlist.push_back("Event/TransMassLepMET4JetPlus_5jet1b");
  plotlist.push_back("Event/TransMassLepMET4JetPlus_5jet2b");
  plotlist.push_back("Event/TransMassLepMET4JetPlus_4jet1b");
  plotlist.push_back("Event/TransMassLepMET4JetPlus_4jet2b");
  plotlist.push_back("Event/TransMassLepMET4JetMinus_5jet1b");
  plotlist.push_back("Event/TransMassLepMET4JetMinus_5jet2b");
  plotlist.push_back("Event/TransMassLepMET4JetMinus_4jet1b");
  plotlist.push_back("Event/TransMassLepMET4JetMinus_4jet2b");

  TFile fnew1("overlay_plots.root", "recreate");
  
  
  
  for(int i=0; i<4; i++){
    TCanvas* c1= new TCanvas((plotlist[i].c_str()),(plotlist[i].c_str()),800,600);
    TH1F* dummy;
 dummy = new TH1F("","",1000,0,2000);
    //if(i==0 || i==1 || i==4 || i==5) dummy = new TH1F("","",100,0,2);
    //if(i==2 || i==3 || i==6 || i ==7) dummy = new TH1F("","",1000,0,2000);
    dummy->GetYaxis()->SetRangeUser(0.1,200);
    //c1->SetLogy();
    //c1->SetGridx();
    //c1->SetGridy();
    dummy->SetTitle(plotlist[i].c_str());
    dummy->Draw();
    TLegend *leg = new TLegend(0.7060302,0.7692308,0.9761307,0.972028,NULL,"brNDC");


    for(int file=0; file<4; file++){
      std::stringstream dir;
      cout<<namelist[file]<<endl;
      dir<<namelist[file];
      TH1F* temp;
      TH1F* tempa;
      TH1F* tempb;

      tempa = (TH1F*) filelist[file]->Get(plotlist[i].c_str());
      temp =  (TH1F*) tempa->Rebin(10, "temp");
      TH1F* temp2;
      tempb = (TH1F*) filelist[file]->Get(plotlist[i+4].c_str());
      temp2 = (TH1F*) tempb->Rebin(10,"temp2");
      temp->Add(temp2);
      float scale = (1.0/nEvtTot[file])*DataLumi[file]*McXsec[file];
      
      temp->Scale(scale);
      c1->cd();
      temp->Draw("SAME");
      temp->SetLineColor(file+1);
      if(file==4){
	temp->Sumw2();
	temp->SetMarkerStyle(23);
	temp->SetLineColor(12);
      }
      leg->AddEntry(temp, namelist[file].c_str(),"lep");

     
      
    }
    c1->cd();
    leg->Draw();
	fnew1.cd();
        c1->Write();
	std::stringstream gif;
	gif<<plotlist[i]<<".gif";

	c1->SaveAs((gif.str()).c_str());
        //      temp_Mjj->Wr
  }
  
}