Beispiel #1
0
void makeqaplot(int run=0, int plt=0, int save=0){
  runnum=run;
  yearday=run/1000;
  if(save==0) {png=0; pdf=0;}
  if(save==1) {png=1; pdf=0;}
  if(save==2) {png=0; pdf=1;}
  if(save==3) {png=1; pdf=1;}

  c1 = new TCanvas("c1","QA",50,50,800,800);
  gStyle->SetLabelSize(0.04,"xy");
  //colortable();
  gStyle->SetPalette(1);
  gStyle->SetStatW(0.4);

  char fname[50];
  if(run==0) {sprintf(fname,"fgtQA.root");}
  else {sprintf(fname,"%d/fgtQA_%d.root",yearday,run);}

  cout << "Opening "<<fname<<endl;
  file=new TFile(fname,"");

  char c[50];
  if(plt==0 || plt==1) {
    gStyle->SetOptStat(111110);
    c1->Divide(1,3); 
    for(int i=0; i<3; i++){
      TVirtualPad* pad = c1->cd(i+1);
      int log=0;
      if(i>0) {log=1;} 
      pad->SetLogy(log); 
      hist0[i]=(TH1F*) file->Get(cHist[i]);
      hist0[i]->SetFillColor(kBlue); 
      hist0[i]->Draw();
      if(i==2){
	float ntot  = float(hist0[i]->GetEntries());
	if(ntot>0.0){
	  int    nbin = hist0[i]->GetNbinsX();
	  float nofgt = hist0[i]->Integral(1,1);	
	  int     bin = hist0[i]->FindBin(float(kFgtNumElecIds));
	  float nonzs = hist0[i]->Integral(bin-1,nbin+1);
	  float    zs = hist0[i]->Integral(2,bin-2);
	  hist0[i]->GetXaxis()->SetRange(2, bin-2);
	  float mean =  hist0[i]->GetMean() / float(kFgtNumElecIds);
	  char c[100];
	  sprintf(c,"Total  %d",ntot);                         TText *t1 = new TText(0.3,0.8,c); t1->SetNDC(); t1->SetTextSize(0.06); t1->Draw();
	  sprintf(c,"NoFGT  %d (%5.2f)",nofgt,nofgt/ntot);     TText *t2 = new TText(0.3,0.7,c); t2->SetNDC(); t2->SetTextSize(0.06); t2->Draw();
	  sprintf(c,"NoneZS %d (%5.2f)",nonzs,nonzs/ntot);     TText *t3 = new TText(0.3,0.6,c); t3->SetNDC(); t3->SetTextSize(0.06); t3->Draw();
	  sprintf(c,"ZS     %d (%5.2f)",zs,zs/ntot);           TText *t4 = new TText(0.3,0.5,c); t4->SetNDC(); t4->SetTextSize(0.06); t4->Draw();
	  sprintf(c,"Mean ZS data size/fullsize= %5.3f",mean); TText *t5 = new TText(0.3,0.4,c); t5->SetNDC(); t5->SetTextSize(0.06); t5->Draw();
	  if(mean>0.08) { t5->SetTextColor(2); }
	  else          { t5->SetTextColor(4); }
	}
      }
    }
    c1->Update();
    save("plot");
  }  
  if(plt==0 || plt==2) {
    c1->Clear();
    gStyle->SetOptStat(0);
    gStyle->SetOptTitle(0);
    c1->Divide(1,3);
    for(int i=3; i<6; i++){ hist0[i]=(TH1F*) file->Get(cHist[i]); }
    int nevt=hist0[5]->GetEntries();
    printf("Nevent=%d\n",nevt);
    TVirtualPad* pad;
    pad=c1->cd(1); pad->SetLogy(); pad->SetTopMargin(0.01); pad->SetRightMargin(0.01);
    hist0[3]->GetXaxis()->SetLabelSize(0.07); hist0[3]->GetYaxis()->SetLabelSize(0.07);     
    hist0[3]->SetFillColor(kRed);  hist0[3]->Scale(1/float(nevt)); hist0[3]->Draw();
    TText *tx= new TText(0.87,0.0,"EleID"); tx->SetNDC(); tx->SetTextSize(0.1); tx->Draw();
    TText *t3= new TText(0.05,0.1,"F3=frac in 3sig/2tb"); t3->SetNDC(); t3->SetTextSize(0.08); t3->SetTextAngle(90); t3->Draw();

    pad=c1->cd(2); pad->SetLogy(); pad->SetTopMargin(0.01); pad->SetRightMargin(0.01);
    hist0[4]->GetXaxis()->SetLabelSize(0.07); hist0[4]->GetYaxis()->SetLabelSize(0.07); 
    hist0[4]->SetFillColor(kBlue); hist0[4]->Scale(1/float(nevt)); hist0[4]->Draw(); 
    tx->Draw();
    TText *t4= new TText(0.05,0.1,"F10=frac in 10sig & >500"); t4->SetNDC(); t4->SetTextSize(0.08); t4->SetTextAngle(90); t4->Draw();

    float min=-4;
    int max=hist0[3]->GetNbinsX();
    printf("Max=%d\n",max);
    TH1F *h1 = new TH1F("ZSdataFrac","ZSdataFrac",50,min,0);
    TH1F *h2 = new TH1F("10SigmaFrac","10SigmaFrac",50,min,0);
    float f1[kFgtNumElecIds],f2[kFgtNumElecIds];
    for(int i=0; i<max; i++){
      f1[i] = log10(hist0[3]->GetBinContent(i+1)); if(f1[i]<min) {f1[i]=min;} h1->Fill(f1[i]);
      f2[i] = log10(hist0[4]->GetBinContent(i+1)); if(f2[i]<min) {f2[i]=min;} h2->Fill(f2[i]);
    }
    pad = c1->cd(3); pad->Divide(2,1);
    TVirtualPad *pad2;
    pad2 = pad->cd(1);
    pad2->SetLogy(); pad2->SetTopMargin(0.01); pad2->SetRightMargin(0.01);
    h1->GetXaxis()->SetLabelSize(0.1); h1->GetYaxis()->SetLabelSize(0.1);
    h2->GetXaxis()->SetLabelSize(0.1); h2->GetYaxis()->SetLabelSize(0.1);
    h1->SetLineColor(kRed);  h2->SetLineColor(kBlue); 
    if(h1->GetMaximum()>h2->GetMaximum()){
      h1->Draw(); h2->Draw("SAME");
    }else{
      h2->Draw(); h1->Draw("SAME");
    }
    TText *t5= new TText(0.2,0.88,"Log(F3)");  t5->SetNDC(); t5->SetTextSize(0.1); t5->SetTextColor(2); t5->Draw();
    TText *t6= new TText(0.6,0.88,"Log(F10)"); t6->SetNDC(); t6->SetTextSize(0.1); t6->SetTextColor(4); t6->Draw();

    //read ped file
    int eid, t;
    float ped[kFgtNumElecIds],rms[kFgtNumElecIds],p,r;
    int status[kFgtNumElecIds]; memset(status,0,sizeof(status));
    cout<<"Reading Ped File "<<endl;
    std::ifstream in("ped.txt");
    if (!in.is_open()) {
      cout << "Can't find file!\n"; 
      exit(0); 
    }   
    while (!in.eof()){
      in >> eid >> t >> p >> r;
      ped[eid]=p;
      rms[eid]=r;
    }  
    in.close();
    TH1F * hr1= new TH1F("RMS","RMS",60,0,120);
    TH1F * hr2= new TH1F("RMS2","RMS2",60,0,120);
    TH1F * hr3= new TH1F("RMS3","RMS3",60,0,120);
    TH1F * hr4= new TH1F("RMS4","RMS4",60,0,120);
    TH1F * hr5= new TH1F("RMS5","RMS5",60,0,120);
    float f1l=-3.5, f1h=-0.5;
    float f2l=-3.5, f2h=-1.2;
    for(int i=0; i<kFgtNumElecIds; i++){
      if(f1[i]<f1l) status[i]+=1;
      if(f1[i]>f1h) status[i]+=2;
      if(f1[i]<f2l) status[i]+=4;
      if(f1[i]>f2h) status[i]+=8;
      hr1->Fill(rms[i]);
      if(f1[i]<f1l) {hr2->Fill(rms[i]);}
      if(f1[i]<f1l || f1[i]>f1h) {hr3->Fill(rms[i]);}
      if(f1[i]<f1l || f1[i]>f1h || f2[i]<f2l) {hr4->Fill(rms[i]);} 
      if(f1[i]<f1l || f1[i]>f1h || f2[i]<f2l || f2[i]>f2h) {hr5->Fill(rms[i]);} 
    }
    char filename[150];
    if(nevt>=1000){
      sprintf(filename,"%d/status/status.%d.txt",yearday,run);
    }else{
      sprintf(filename,"%d/status/status.%d.lowstat.txt",yearday,run);
    }
    FILE* pfile=fopen(filename,"w");
    if(!pfile){
      printf("Couldn't open file %s\n",filename);
    }else{
      printf("Writing %s\n",filename);
      for(int i=0; i<kFgtNumElecIds; i++){
	fprintf(pfile,"%d 0x%d\n",i,status[i]);
      }
      fclose(pfile);
    }
    
    pad2 = pad->cd(2);
    pad2->SetLogy(0); pad2->SetTopMargin(0.01); pad2->SetRightMargin(0.01);
    hr1->GetXaxis()->SetLabelSize(0.1); hr1->GetYaxis()->SetLabelSize(0.05);
    hr1->SetFillColor(3); hr1->Draw(); 
    hr5->SetFillColor(9); hr5->Draw("same"); 
    hr4->SetFillColor(4); hr4->Draw("same"); 
    hr3->SetFillColor(6); hr3->Draw("same"); 
    hr2->SetFillColor(2); hr2->Draw("same"); 
    char cc1[100]; sprintf(cc1,"Log(F3)<%4.1f",f1l);
    char cc2[100]; sprintf(cc2,"Log(F3)>%4.1f",f1h);
    char cc3[100]; sprintf(cc3,"Log(F10)<%4.1f",f2l);
    char cc4[100]; sprintf(cc4,"Log(F10)>%4.1f",f2h);
    TText *t7 = new TText(0.6,0.88,cc1);   t7->SetNDC();  t7->SetTextSize(0.07);  t7->SetTextColor(2);  t7->Draw();
    TText *t8 = new TText(0.6,0.78,cc2);   t8->SetNDC();  t8->SetTextSize(0.07);  t8->SetTextColor(6);  t8->Draw();
    TText *t9 = new TText(0.6,0.68,cc3);   t9->SetNDC();  t9->SetTextSize(0.07);  t9->SetTextColor(4);  t9->Draw();
    TText *t10= new TText(0.6,0.58,cc4);   t10->SetNDC(); t10->SetTextSize(0.07); t10->SetTextColor(9); t10->Draw();
    TText *t11= new TText(0.6,0.48,"OK");  t11->SetNDC(); t11->SetTextSize(0.07); t11->SetTextColor(3); t11->Draw();
    TText *t12= new TText(0.8,0.15,"PedRMS"); t12->SetNDC(); t12->SetTextSize(0.07); t12->Draw();
    c1->Update();
    save("frac");
  }
Beispiel #2
0
/** 
 * 
 * 
 * @param o 
 * @param useWeights 
 * @param correct
 *
 * @ingroup pwglf_forward_scripts_tests
 */
void
TestPoisson(Double_t o=.3, bool useWeights=false, bool correct=true)
{
  const char* load = "$ALICE_PHYSICS/PWGLF/FORWARD/analysis2/scripts/LoadLibs.C";
  if (!gROOT->GetClass("AliAODForwardMult")) {
    gROOT->Macro(load);
    gROOT->GetInterpreter()->UnloadFile(gSystem->ExpandPathName(load));
  }
  
  // --- Parameters of this script -----------------------------------
  Int_t      nBin =  5;  // Our detector matrix size 
  Int_t      nMax = TMath::Max(Int_t(nBin * nBin * o + .5)+nBin/2,nBin);  
  Int_t      nEv  = 10000; // Number of events
  Double_t   mp   = o;   // The 'hit' probability 


  TH2D* base = new TH2D("base", "Basic histogram", 
			nBin,-.5, nBin-.5, nBin, -.5, nBin-.5);
  base->SetXTitle("#eta");
  base->SetYTitle("#varphi");
  base->SetDirectory(0);
  base->SetOption("colz");

  Int_t tN1=nMax;    Double_t tMin1; Double_t tMax1;
  Int_t tN2=nMax*10; Double_t tMin2; Double_t tMax2=nMax;
  MakeIntegerAxis(tN1, tMin1, tMax1);
  MakeIntegerAxis(tN2, tMin2, tMax2);
  TH2D* corr = new TH2D("comp", "Comparison", 
			tN1, tMin1, tMax1, tN2, tMin2, tMax2);
  corr->SetXTitle("Input");
  corr->SetYTitle("Poisson");
  corr->SetDirectory(0);
  corr->SetOption("colz");
  corr->SetStats(0);
  TLine* lcorr = new TLine(0, 0, tMax2, tMax2);

  Int_t mm = TMath::Max(Int_t(nBin * o + .5),nBin/2);
  tN2=mm*10; tMax2 = mm;
  MakeIntegerAxis(tN2, tMin2, tMax2);
  Info("", "Making mean w/nbins=%d,range=[%f,%f]", tN2, tMin2, tMax2);
  TH2D* mean = new TH2D("mean", "Mean comparison", 
			tN2, tMin2, tMax2, tN2, tMin2, tMax2);
  mean->SetXTitle("Input");
  mean->SetYTitle("Poisson");
  mean->SetDirectory(0);
  mean->SetOption("colz");
  mean->SetStats(0);
  TLine* lmean = new TLine(tMin2, tMin2, tMax2, tMax2);

  TH1D* dist = new TH1D("dist", "Distribution of hits", tN1, tMin1, tMax1);
  dist->SetXTitle("s");
  dist->SetYTitle("P(s)");
  dist->SetFillColor(kRed+1);
  dist->SetFillStyle(3001);
  dist->SetDirectory(0);

  TH1D* diff = new TH1D("diff", "P-T", 100, -25, 25);
  diff->SetXTitle("Difference");
  diff->SetFillColor(kRed+1);
  diff->SetFillStyle(3001);
  diff->SetYTitle("Prob");

  AliPoissonCalculator* c = new AliPoissonCalculator("ignored");
  c->Init(nBin ,nBin);

  for (Int_t i = 0; i < nEv; i++) { 
    c->Reset(base);
    base->Reset();

    for (Int_t iEta = 0; iEta < nBin; iEta++) { 
      for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { 
	// Throw a die 
	Int_t m = gRandom->Poisson(mp);
	dist->Fill(m);

	// Fill into our base histogram 
	base->Fill(iEta, iPhi, m);

	// Fill into poisson calculator 
	c->Fill(iEta, iPhi, m > 0, (useWeights ? m : 1));
      }
    }
    // Calculate the result 
    TH2D* res = c->Result(correct);
    
    // Now loop and compare 
    Double_t mBase = 0;
    Double_t mPois = 0;
    for (Int_t iEta = 0; iEta < nBin; iEta++) { 
      for (Int_t iPhi = 0; iPhi < nBin; iPhi++) { 
	Double_t p = res->GetBinContent(iEta, iPhi);
	Double_t t = base->GetBinContent(iEta, iPhi);

	mBase += t;
	mPois += p;
	corr->Fill(t, p);
	diff->Fill(p-t);
      }
    }
    Int_t nn = nBin * nBin;
    mean->Fill(mBase / nn, mPois / nn);
  }

  TCanvas* cc = new TCanvas("c", "c", 900, 900);
  cc->SetFillColor(0);
  cc->SetFillStyle(0);
  cc->SetBorderMode(0);
  cc->SetRightMargin(0.02);
  cc->SetTopMargin(0.02);
  cc->Divide(2,2);
  
  TVirtualPad* pp = cc->cd(1);
  pp->SetFillColor(0);
  pp->SetFillStyle(0);
  pp->SetBorderMode(0);
  pp->SetRightMargin(0.15);
  pp->SetTopMargin(0.02);
  pp->SetLogz();
  pp->SetGridx();
  pp->SetGridy();
  corr->Draw();
  lcorr->Draw();

  pp = cc->cd(2);
  pp->SetFillColor(0);
  pp->SetFillStyle(0);
  pp->SetBorderMode(0);
  pp->SetRightMargin(0.02);
  pp->SetTopMargin(0.02);
#if 0
  c->GetMean()->Draw();
#elif 1 
  pp->SetLogy();
  diff->Draw();
#elif 1
  c->GetOccupancy()->Draw();
#else
  pp->SetLogy();
  dist->SetStats(0);
  dist->Scale(1. / dist->Integral());
  dist->Draw();
  TH1D* m1 = c->GetMean();
  m1->Scale(1. / m1->Integral());
  m1->Draw("same");
  Double_t eI;
  Double_t ii = 100 * dist->Integral(2, 0);
  TLatex* ll = new TLatex(.97, .85, 
			  Form("Input #bar{m}: %5.3f", mp));
  ll->SetNDC();
  ll->SetTextFont(132);
  ll->SetTextAlign(31);
  ll->Draw();
  ll->DrawLatex(.97, .75, Form("Result #bar{m}: %5.3f", dist->GetMean()));
  ll->DrawLatex(.97, .65, Form("Occupancy: #int_{1}^{#infty}P(s)ds = %6.2f%%",
			       ii));
			 
#endif

  pp = cc->cd(3);
  pp->SetFillColor(0);
  pp->SetFillStyle(0);
  pp->SetBorderMode(0);
  pp->SetRightMargin(0.15);
  pp->SetTopMargin(0.02);
  pp->SetGridx();
  pp->SetGridy();
  c->GetCorrection()->Draw();

  pp = cc->cd(4);
  pp->SetFillColor(0);
  pp->SetFillStyle(0);
  pp->SetBorderMode(0);
  pp->SetRightMargin(0.15);
  pp->SetTopMargin(0.02);
  pp->SetLogz();
  pp->SetGridx();
  pp->SetGridy();
  mean->Draw();
  lmean->Draw();

  cc->cd();
}
Beispiel #3
0
void validation()
{
	msglvl[DBG] = SILENT;
	msglvl[INF] = VISUAL;
	msglvl[WRN] = VISUAL;
	msglvl[ERR] = VISUAL;
	msglvl[FAT] = VISUAL;

	TDirectory* oldDir = gDirectory; // remember old directory

	style();

	Int_t g4bin = (ng4bins/g4max+1); //==> g^4=1 ==> SSM !
	
	TString suffix = "";
	if(doTruth) suffix = "_truth";
	
	TString mctype  = (isMC11c) ? "mc11c" : "mc11a";
	
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_overallEWkF_noInAmpSigEWkF_noHighMbins_wthOfficialZP_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_mc11c_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_treeLevelMass_Xmass2000.root";
	// TString fBGname = "plots/ZP_2dtemplates_"+mctype+"_33st_noKKtmplates_overallEWkF_noInAmpSigEWkF_noTruth_wthOfficialZP_fixedBWwidth_treeLevelMass_Xmass2000.root";

	TLegend* legR = new TLegend(0.15,0.75,0.35,0.85,NULL,"brNDC");
	legR->SetFillStyle(4000); //will be transparent
	legR->SetFillColor(0);
	legR->SetTextFont(42);
	TH1D* hDummy = new TH1D("","",1,0.,1.);
	hDummy->SetMarkerStyle(20);
	hDummy->SetMarkerSize(0.8);
	hDummy->SetMarkerColor(kBlack);
	if(!doResiduals) legR->AddEntry(hDummy,"#frac{template}{official}","lep");
	else             legR->AddEntry(hDummy,"#frac{template - official}{#sqrt{#delta^{2}template + #delta^{2}official}}","lep");
	
	TPaveText* ptxt = new TPaveText(0.145,0.35,0.245,0.55,"NDC");
	TText* txt;
	ptxt->SetTextSize(0.03);
	ptxt->SetBorderSize(0);
	ptxt->SetFillStyle(4000); //will be transparent
	ptxt->SetFillColor(0);
	ptxt->SetTextAlign(12);
	txt = ptxt->AddText("This range");
	txt = ptxt->AddText("is chopped");
	txt = ptxt->AddText("before the");
	txt = ptxt->AddText("template is");
	txt = ptxt->AddText("handed to");
	txt = ptxt->AddText("BAT (limit).");
	
	oldDir->cd();

	TString fBGname = "plots/validation/ZP_2dtemplates_mc11c_33st_noKKtmplates_wthOfficialZP_treeLevelMass_Xmass2000.root";
	TFile* fD = new TFile(fBGname,"READ");
	TH1D* hDY = NULL;
	if(doTruth) hDY = (TH1D*)fD->Get("hMass_DYmumu_truth")->Clone();
	else        hDY = (TH1D*)fD->Get("hMass_DYmumu")->Clone();
	hDY->SetLineColor(kMagenta-5);
	hDY->SetMarkerColor(kMagenta-5);

	oldDir->cd();

	TFile* fDYrozmin    = new TFile("plots/mass_plot_tables_3st.root","READ");
	TH1D* hDYrozmin = (TH1D*)fDYrozmin->Get("mass_log_dy")->Clone();
	hDYrozmin = (TH1D*)hGeV2TeV(hDYrozmin)->Clone();
	hDYrozmin = (TH1D*)hChopper(hDYrozmin,bins2chop)->Clone();
	oldDir->cd();
	TFile* f1dTemplates = new TFile("plots/ZpSignal_MM_MC11c_5points.root","READ");
	TObjArray* toarr1d = new TObjArray();
	toarr1d->Read("template");
	TMapTSP2TH1D h1dBrandeisTmpltMap;
	double Nflat = 399948;
	double sigmaflat = 4.3988E+07*nb2fb;
	double Lmcflat = Nflat/sigmaflat;
	double scale = luminosity/Lmcflat;
	TH1D* h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(0/*22*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(1/*28*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(2/*34*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(3/*40*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) );
	h1dTmp = NULL;
	h1dTmp = (TH1D*)((TObjArray*)toarr1d->At(4/*47*/))->Clone();
	h1dTmp->Scale(scale);
	h1dTmp = (TH1D*)hChopper(h1dTmp,bins2chop)->Clone();
	h1dTmp->Add(hDYrozmin);
	h1dBrandeisTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) );

	oldDir->cd();

	TMapTSP2TH1D h1Map;
	h1Map.insert( make_pair("1000o", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) );
	h1Map.insert( make_pair("1000t", (TH1D*)fD->Get("hMass_Zprime_SSM1000_template"+suffix)->Clone()) );
	if(isMC11c)
	{
		h1Map.insert( make_pair("1250o", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) );
		h1Map.insert( make_pair("1250t", (TH1D*)fD->Get("hMass_Zprime_SSM1250_template"+suffix)->Clone()) );
	}
	h1Map.insert( make_pair("1500o", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) );
	h1Map.insert( make_pair("1500t", (TH1D*)fD->Get("hMass_Zprime_SSM1500_template"+suffix)->Clone()) );
	h1Map.insert( make_pair("1750o", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) );
	h1Map.insert( make_pair("1750t", (TH1D*)fD->Get("hMass_Zprime_SSM1750_template"+suffix)->Clone()) );
	h1Map.insert( make_pair("2000o", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) );
	h1Map.insert( make_pair("2000t", (TH1D*)fD->Get("hMass_Zprime_SSM2000_template"+suffix)->Clone()) );

	TMapTSP2TH1D h1rMap;
	h1rMap.insert( make_pair("1000", (TH1D*)fD->Get("hMass_Zprime_SSM1000"+suffix)->Clone()) );
	if(isMC11c) h1rMap.insert( make_pair("1250", (TH1D*)fD->Get("hMass_Zprime_SSM1250"+suffix)->Clone()) );
	h1rMap.insert( make_pair("1500", (TH1D*)fD->Get("hMass_Zprime_SSM1500"+suffix)->Clone()) );
	h1rMap.insert( make_pair("1750", (TH1D*)fD->Get("hMass_Zprime_SSM1750"+suffix)->Clone()) );
	h1rMap.insert( make_pair("2000", (TH1D*)fD->Get("hMass_Zprime_SSM2000"+suffix)->Clone()) );
	for(TMapTSP2TH1D::iterator it=h1rMap.begin() ; it!=h1rMap.end() ; ++it)
	{
		it->second->Reset();
		if(!doResiduals) it->second->Divide(h1Map[it->first+"o"],h1Map[it->first+"t"],1.,1.,"B");
		else             residuals(h1Map[it->first+"o"], h1Map[it->first+"t"], it->second);
		
		// for(Int_t i=0 ; i<=it->second->GetNbinsX()+1 ; i++) it->second->SetBinError(i,0);
		it->second->SetMarkerStyle(20);
		it->second->SetMarkerSize(0.5);
		it->second->GetXaxis()->SetLabelSize(0.073);
		it->second->GetYaxis()->SetLabelSize(0.073);
		it->second->GetXaxis()->SetTitleSize(0.073);
		it->second->GetYaxis()->SetTitleSize(0.073);
		it->second->SetTitleSize(0.075);
		it->second->GetYaxis()->SetTitleOffset(0.5);
		if(!doResiduals)
		{
			it->second->SetMinimum(0.2);
			it->second->SetMaximum(1.8);
		}
		else
		{
			it->second->SetMinimum(-5.);
			it->second->SetMaximum(+5.);
		}
		it->second->SetTitle("");
		if(!doResiduals) it->second->GetYaxis()->SetTitle("ratio");
		else             it->second->GetYaxis()->SetTitle("residuals");
	}

	TMapTSP2TGAE poissonGraphMap;
	TMapTSP2TLeg legMap;


	_INFO("");

	oldDir->cd();

	fD->cd();	
	TH1D* h1Template = (TH1D*)fD->Get("hMass_DYmumu"+suffix)->Clone();
	h1Template->Reset();
	TObjArray* toarr = new TObjArray();
	if(doTruth) toarr->Read("truth_template2d");
	else        toarr->Read("template2d");
	TH2D* h2SSM2000 = (TH2D*)((TObjArray*)toarr->At(0))->Clone("hMass"+suffix+"_Zprime_SSM2000_template2d");
	for(Int_t bin=1 ; bin<=h2SSM2000->GetNbinsX() ; bin++)
	{
		h1Template->SetBinContent(bin, h2SSM2000->GetBinContent(bin,g4bin));
		h1Template->SetBinError(bin, h2SSM2000->GetBinError(bin,g4bin));
	}
	h1Template->SetLineColor(kViolet);
	h1Template->SetLineWidth(1);
	h1Template->SetMarkerStyle(20);
	h1Template->SetMarkerSize(0.3);
	h1Template->SetMarkerColor(kViolet);
	// the functions
	h2Template = (TH2D*)h2SSM2000->Clone();
	vector<TF1*> vfunc;
	unsigned int nmllbins = h2Template->GetNbinsX();
	for(unsigned int mll=1 ; mll<=(nmllbins-bins2chop) ; mll++) // 1...(56-9 = 47)
	{
		TString mllname = (TString)_s(mll);
		TString mllval  = (TString)_s(h2Template->GetXaxis()->GetBinCenter(mll+bins2chop));
		
		TF1* f = new TF1("fNominal_mll"+mllname,fTH1toTF1,g4min,g4max,1);
		f->SetParameter(0,mll);
		f->SetParNames("mll");
		// f->SetLineColor(kBlue);
		// f->SetLineWidth(1);
		f->SetNpx(400);
		vfunc.push_back(f);
	}
	TGraph* graphDY = new TGraph();
	graphDY->SetMarkerStyle(25);
	graphDY->SetMarkerSize(0.6);
	graphDY->SetMarkerColor(kGreen+2);
	TGraph* graphSSM = new TGraph();
	graphSSM->SetMarkerStyle(24);
	graphSSM->SetMarkerSize(0.6);
	graphSSM->SetMarkerColor(kOrange+8);
	for(unsigned int i=0 ; i<vfunc.size() ; i++)
	{
		double DY = vfunc[i]->Eval(0.0);
		double SSM = vfunc[i]->Eval(1.0);
		graphDY->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),DY);
		graphSSM->SetPoint(i,h2Template->GetXaxis()->GetBinCenter(bins2chop+i+1),SSM);
	}
	
	
	oldDir->cd();

	TObjArray* toarr1dTLV = new TObjArray();
	TMapTSP2TH1D h1dTlvTmpltMap;
	TFile* fT = NULL;
	TString fTname = "plots/validation/ZP_2dtemplates_mc11c_33st_noInterference_noKKtmplates_noOverallEWkF_wthOfficialZP_treeLevelMass_Xmass";
	
	fT = new TFile(fTname+"1000.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1000",(TH1D*)resetErrors(h1dTmp)->Clone("1000")) );
	fT = new TFile(fTname+"1250.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1250",(TH1D*)resetErrors(h1dTmp)->Clone("1250")) );
	fT = new TFile(fTname+"1500.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1500",(TH1D*)resetErrors(h1dTmp)->Clone("1500")) );
	fT = new TFile(fTname+"1750.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("1750",(TH1D*)resetErrors(h1dTmp)->Clone("1750")) );
	fT = new TFile(fTname+"2000.root","READ");
	toarr1dTLV->Read("template");
	h1dTmp = (TH1D*)((TObjArray*)toarr1dTLV->At(0))->Clone();
	h1dTmp->Add(hDY);
	h1dTlvTmpltMap.insert( make_pair("2000",(TH1D*)resetErrors(h1dTmp)->Clone("2000")) );

	oldDir->cd();
	
	
	for(TMapTSP2TH1D::iterator it=h1Map.begin() ; it!=h1Map.end() ; ++it)
	{
		if(it->first.Contains("o"))
		{
			TString name = it->first;
			name.ReplaceAll("o","");
			it->second->SetFillColor(kAzure-9);
			if(doTruth) it->second->SetTitle("m_{Z'} = "+name+" GeV (truth)");
			else        it->second->SetTitle("m_{Z'} = "+name+" GeV");
		}
		if(it->first.Contains("t"))
		{
			//TGraphAsymmErrors* poisson(TH1D* h)
			it->second->SetLineColor(kBlue);
			it->second->SetMarkerStyle(20);
			it->second->SetMarkerSize(0.4);
			it->second->SetMarkerColor(kBlue);
			it->second->SetLineWidth(1);
			
			TString name = it->first;
			name.ReplaceAll("t","");
			poissonGraphMap.insert( make_pair(name, (TGraphAsymmErrors*)poisson(it->second)->Clone()) );
			poissonGraphMap[name]->SetMarkerStyle(20);
			poissonGraphMap[name]->SetMarkerSize(0.3);
			poissonGraphMap[name]->SetMarkerColor(kBlue);
			poissonGraphMap[name]->SetLineWidth(1);
			poissonGraphMap[name]->SetLineColor(kBlue);
		}
	}	

	Double_t yLine = (!doResiduals) ? 1. : 0.;

	TLine* line = new TLine(0.07,yLine,3.,yLine);	
	line->SetLineColor(kRed);
	line->SetLineWidth(2);
	
	TMapTSP2TCNV cnvMap;
	cnvMap.insert( make_pair("1000", new TCanvas("1000","1000",600,550)) );
	if(isMC11c) cnvMap.insert( make_pair("1250", new TCanvas("1250","1250",600,550)) );
	cnvMap.insert( make_pair("1500", new TCanvas("1500","1500",600,550)) );
	cnvMap.insert( make_pair("1750", new TCanvas("1750","1750",600,550)) );
	cnvMap.insert( make_pair("2000", new TCanvas("2000","2000",600,550)) );
	for(TMapTSP2TCNV::iterator it=cnvMap.begin() ; it!=cnvMap.end() ; ++it)
	{
		_INFO("starting "+(string)it->first);
		if(it->first=="2000") legMap.insert( make_pair(it->first, new TLegend(0.35,0.55,0.83,0.84,NULL,"brNDC")) );
		else                  legMap.insert( make_pair(it->first, new TLegend(0.35,0.60,0.83,0.84,NULL,"brNDC")) );
		legMap[it->first]->SetFillStyle(4000); //will be transparent
		legMap[it->first]->SetFillColor(0);
		legMap[it->first]->SetTextFont(42);
		legMap[it->first]->AddEntry(h1Map[it->first+"o"],"Official Z'_{SSM}","F");
		legMap[it->first]->AddEntry(hDY,"Official DY#mu#mu","lep");
		legMap[it->first]->AddEntry(h1Map[it->first+"t"],"ME^{2} method: Template w/o couplings scale","lep");
		if(it->first=="2000")
		{
			legMap[it->first]->AddEntry(h1Template,"ME^{2} method: Template histogram at  #it{g=1} (SSM)","lep");
			legMap[it->first]->AddEntry(graphSSM,  "ME^{2} method: Template function  at  #it{g=1} (SSM)","p");
			legMap[it->first]->AddEntry(graphDY,   "ME^{2} method: Template function  at  #it{g=0} (DY)","p");
		}
		if(!doTruth)
		{
			h1dTlvTmpltMap[it->first]->SetLineColor(kCyan+2);
			h1dTlvTmpltMap[it->first]->SetMarkerColor(kCyan+2);
			h1dTlvTmpltMap[it->first]->SetMarkerStyle(5);
			h1dTlvTmpltMap[it->first]->SetMarkerSize(0.5);
			legMap[it->first]->AddEntry(h1dTlvTmpltMap[it->first],"ME^{2} method: DY+Template (no interference)","p");
		
			h1dBrandeisTmpltMap[it->first]->SetLineColor(kRed);
			h1dBrandeisTmpltMap[it->first]->SetMarkerColor(kRed);
			h1dBrandeisTmpltMap[it->first]->SetMarkerStyle(27);
			h1dBrandeisTmpltMap[it->first]->SetMarkerSize(0.5);
			legMap[it->first]->AddEntry(h1dBrandeisTmpltMap[it->first],"Flat Z' method: DY+Template (no interference)","p");
		}

		it->second->Divide(1,2);
		TVirtualPad* ph = it->second->cd(1);
		TVirtualPad* pr = it->second->cd(2);	
		ph->SetPad(0.00, 0.35, 1.00, 1.00);
		pr->SetPad(0.00, 0.00, 1.00, 0.35);
		ph->SetBottomMargin(0.012);
		pr->SetBottomMargin(0.20);
		pr->SetTopMargin(0.012);
		
		ph->cd();
		ph->Draw();
		ph->SetTicks(1,1);
		ph->SetLogy();
		ph->SetLogx();
		// h1Map[it->first+"o"]->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 );
		// h1Map[it->first+"o"]->Draw();
		TH1D* hTmpNoErr = (TH1D*)resetErrors(h1Map[it->first+"o"])->Clone();
		hTmpNoErr->SetMaximum( h1Map[it->first+"t"]->GetMaximum()*1.5 );
		hTmpNoErr->SetLineStyle(1);
		hTmpNoErr->SetLineColor(kBlack);
		hTmpNoErr->SetFillColor(kAzure-9);
		hTmpNoErr->Draw();
		TH1D* hTmpErr = (TH1D*)ShiftLog(h1Map[it->first+"o"],0.2)->Clone();
		hTmpErr->SetFillStyle(4000); //will be transparent
		hTmpErr->SetFillColor(0);
		hTmpErr->DrawCopy("epx0SAMES");
		hDY->Draw("SAMES");
		h1Map[it->first+"t"]->Draw("epSAMES");
		//poissonGraphMap[it->first]->Draw("pSAMES");
		if(it->first=="2000")
		{
			graphDY->Draw("SAMESp");
			graphSSM->Draw("SAMESp");
			h1Template->Draw("epSAMES");
		}
		_INFO("");
		h1dTlvTmpltMap[it->first]->Draw("SAMESp");
		h1dBrandeisTmpltMap[it->first]->Draw("SAMESp");
		
		TLine* chopline = new TLine(0.12805,getYmin(h1Map[it->first+"o"]),0.12805,7.e5);
		chopline->SetLineStyle(2);
		chopline->SetLineColor(kBlack);
		chopline->Draw("SAMES");
		ptxt->Draw("SAMES");
		
		legMap[it->first]->Draw("SAMES");
		ph->RedrawAxis();
		ph->Update();

		_INFO("");

		pr->cd();
		pr->Draw();
		pr->SetTicks(1,1);
		pr->SetGridy();
		pr->SetLogx();
		h1rMap[it->first]->Draw("ep");
		line->Draw("SAMES");
		h1rMap[it->first]->Draw("epSAMES");
		legR->Draw("SAMES");
		pr->RedrawAxis();
		pr->Update();

		unsigned int savestate = 1;
		if(it->first=="1000")      savestate = 0;
		else if(it->first=="2000") savestate = 2;
		else                       savestate = 1;
		TString testType = (doResiduals) ? "_residuals" : "_ratio";
		mutype   = (doTruth)     ? "_truth"     : "_recon";
		savemultipdf(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_all.pdf", savestate);
		saveas(it->second, "plots/validation/validation"+mutype+testType+"_"+mctype+"_"+it->first);
		
		TCanvas* c = new TCanvas(it->first,"",600,400);
		c->cd();
		c->Draw();
		c->SetTicks(1,1);
		c->SetLogy();
		c->SetLogx();
		hTmpNoErr->Draw();
		hTmpErr->DrawCopy("epx0SAMES");
		hDY->Draw("SAMES");
		h1Map[it->first+"t"]->Draw("epSAMES");
		//poissonGraphMap[it->first]->Draw("pSAMES");
		if(it->first=="2000")
		{
			graphDY->Draw("SAMESp");
			graphSSM->Draw("SAMESp");
			h1Template->Draw("epSAMES");
		}
		h1dTlvTmpltMap[it->first]->Draw("SAMESp");
		h1dBrandeisTmpltMap[it->first]->Draw("SAMESp");
		legMap[it->first]->Draw("SAMES");
		chopline->Draw("SAMES");
		ptxt->Draw("SAMES");
		c->RedrawAxis();
		c->Update();
		saveas(c,"plots/validation/validation_"+it->first+"_"+mutype+testType);
		
		_INFO("done "+(string)it->first);
	}
}
Beispiel #4
0
void draw_R2m(void)
{
	const double er[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
	double ccnt[9];
	double eccnt[9];
	double dcnt[9];
	TGraphErrors *gr;
	TGraphErrors *grd;
	TH1D *hst;
	TH1D *hstd;
	double effUp, effDown, C, shift, size;
	double eeffUp, eeffDown, eC, eshift, esize;
	double fmin, fedm, errdef;
	int npari, nparx;
	int i, irc;
	char str[1024];
	TF1 *fR2;
	TVirtualPad *pd;
	
	gStyle->SetOptStat(0);
	gStyle->SetOptFit(0);
	
	MyMinuit = new TMinuit(5);
	MyMinuit->SetFCN(chi2fun);
	MyMinuit->DefineParameter(0, "Const", 1000, 10, 0, 1E10);
	MyMinuit->DefineParameter(1, "EffUp", 1, 0.1, 0.5, 1.5);
	MyMinuit->DefineParameter(2, "EffDown", 1, 0.1, 0.5, 1.5);
	MyMinuit->DefineParameter(3, "Shift", 0, 0.1, -10, 10);
	MyMinuit->DefineParameter(4, "Size", 3, 1, 0, 10);
	MyMinuit->FixParameter(3);
	MyMinuit->FixParameter(4);
	MyMinuit->Migrad();
	MyMinuit->GetParameter(0, C, eC);
	MyMinuit->GetParameter(1, effUp, eeffUp);
	MyMinuit->GetParameter(2, effDown, eeffDown);
	MyMinuit->GetParameter(3, shift, eshift);
	MyMinuit->GetParameter(4, size, esize);
	MyMinuit->mnstat(fmin, fedm, errdef, npari, nparx, irc);

//		Renorm top and bottom sections to the middle
	for (i=0; i<3; i++) {
		ccnt[i] = DataArray.cnt[i] / effUp;
		ccnt[i+3] = DataArray.cnt[i+3];
		ccnt[i+6] = DataArray.cnt[i+6] / effDown;
		eccnt[i] = DataArray.ecnt[i] / effUp;
		eccnt[i+3] = DataArray.ecnt[i+3];
		eccnt[i+6] = DataArray.ecnt[i+6] / effDown;
	}
//	for (i=0; i<9; i++) printf("L = %8.3f    CNT = %6.1f +- %4.1f\n", r[i], cnt[i], ecnt[i]);
	gr = new TGraphErrors(9, DataArray.r, ccnt, er, eccnt);
	gr->SetLineColor(kBlue);
	gr->SetLineWidth(4);
	gr->SetMarkerStyle(20);
	gr->SetMarkerColor(kBlue);
	gr->SetMarkerSize(2);
	
	fR2 = new TF1("fR2", "[0] / ((x - [1]) * (x - [1]) - [2] * [2] / 4.0)", 1, 100);
	fR2->SetParameter(0, C);
	fR2->SetParameter(1, shift);
	fR2->SetParameter(2, size);
	fR2->SetLineColor(kRed);
	fR2->SetLineWidth(3);
	
	hst = new TH1D("H", ";Distance to reactor core center, m;Events per day", 35, 10, 13.5);
	hst->SetMinimum(DataArray.cnt[4] * 0.5);
	hst->SetMaximum(DataArray.cnt[4] * 1.5);
	hst->GetXaxis()->SetLabelSize(0.06);
	hst->GetYaxis()->SetLabelSize(0.06);
	hst->GetXaxis()->SetTitleSize(0.06);
	hst->GetYaxis()->SetTitleSize(0.06);
	hst->GetYaxis()->SetTitleOffset(1.25);

	hstd = new TH1D("H", ";Distance to reactor core center, m;Events per day", 35, 10, 13.5);
	hstd->SetMinimum(-40);
	hstd->SetMaximum(40);
	hstd->GetXaxis()->SetLabelSize(0.06);
	hstd->GetYaxis()->SetLabelSize(0.06);
	hstd->GetXaxis()->SetTitleSize(0.06);
	hstd->GetYaxis()->SetTitleSize(0.06);
	hstd->GetYaxis()->SetTitleOffset(1.25);
	
	TCanvas *cv = new TCanvas("CV", "R2", 800, 1200);
	cv->Divide(1, 2);
//		Do common fit and draw
	pd = cv->cd(1);
	pd->SetLeftMargin(0.15);
	pd->SetBottomMargin(0.15);
	pd->SetTopMargin(0.03);
	hst->Draw();
	gr->Draw("p");
	fR2->Draw("same");
	TLatex txt;
	txt.SetTextSize(0.07);
	sprintf(str, "#chi^{2}/n.d.f. = %6.2f/5", fmin);
	txt.DrawLatex(11.3, DataArray.cnt[4] * 1.3, str);
//		Draw difference
	for (i=0; i<9; i++) dcnt[i] = ccnt[i] - fR2->Eval(DataArray.r[i]);
	grd = new TGraphErrors(9, DataArray.r, dcnt, er, eccnt);
	grd->SetLineColor(kBlue);
	grd->SetLineWidth(4);
	grd->SetMarkerStyle(20);
	grd->SetMarkerColor(kBlue);
	grd->SetMarkerSize(2);
	
	pd = cv->cd(2);
	pd->SetLeftMargin(0.15);
	pd->SetBottomMargin(0.15);
	pd->SetTopMargin(0.03);
	hstd->Draw();
	grd->Draw("p");
}
///
/// Plot the evolution of best fit nuisance paramters
/// along the 1-CL curve.
///
/// By changing the code at the beginning of the function
/// one can chose whether all scan results are plotted, or
/// only those comprising the 1-CL curve.
///
void ParameterEvolutionPlotter::plotParEvolution()
{
	vector<RooSlimFitResult*> results = allResults;
	// vector<RooSlimFitResult*> results = curveResults;

	cout << "ParameterEvolutionPlotter::plotParEvolution() : plotting ..." << endl;
	selectNewCanvas(title+" 1");

	// get all parameters, loop over them
	TIterator* it = w->set(parsName)->createIterator();
	while ( RooRealVar* p = (RooRealVar*)it->Next() )
	{
		if ( p->isConstant() && p->GetName()!=scanVar1 ) continue;
		if ( arg->debug ) cout << "ParameterEvolutionPlotter::plotParEvolution() : var = " << p->GetName() << endl;
		TVirtualPad *pad = selectNewPad();
		pad->SetLeftMargin(0.25);
		pad->SetTopMargin(0.10);
		// create a graph of the nominal evolution of one parameter
		TGraph *g = makeEvolutionGraph(curveResults, p->GetName());
		g->SetTitle(p->GetTitle());
		g->GetXaxis()->SetTitle(scanVar1);
		g->GetXaxis()->SetTitleSize(0.08);
		g->GetXaxis()->SetLabelSize(0.06);
		g->GetXaxis()->SetNdivisions(-406);
		g->GetYaxis()->SetTitleSize(0.08);
		g->GetYaxis()->SetLabelSize(0.06);
		g->GetYaxis()->SetTitleOffset(1.4);
		g->GetYaxis()->SetTitle(p->GetName());
		g->SetLineColor(kBlue);
		g->SetLineWidth(2);
		TGaxis::SetMaxDigits(3); // forces scienfific notation
		g->Draw("al");
		// add error bands
		TGraphErrors *g2 = makeEvolutionGraphErrors(curveResults, p->GetName());
		g2->SetFillColorAlpha(kBlue,0.15);
		g2->Draw("3");
		// create a graph of the full evolution of one parameter
		if ( arg->isQuickhack(16) ){
			TGraph *g3 = makeEvolutionGraph(allResults, p->GetName());
			g3->Draw("p");
		}
		updateCurrentCanvas();
		// plot a red line at minimum
		drawLinesAtMinima(pad);
	}

	// plot the chi2 to the last pad
	TVirtualPad *pad = selectNewPad();
	pad->SetLeftMargin(0.25);
	TGraph *g = makeChi2Graph(curveResults);
	g->SetLineWidth(2);
	g->SetTitle("chi2");
	g->GetXaxis()->SetTitle(scanVar1);
	g->GetXaxis()->SetTitleSize(0.08);
	g->GetXaxis()->SetLabelSize(0.06);
	g->GetXaxis()->SetNdivisions(-406);
	g->GetYaxis()->SetTitleSize(0.08);
	g->GetYaxis()->SetLabelSize(0.06);
	g->GetYaxis()->SetTitleOffset(1.4);
	g->GetYaxis()->SetTitle("#chi^{2}");
	g->Draw("al");
	drawLinesAtMinima(pad);
	updateCurrentCanvas();
	// save plots
	saveEvolutionPlots();
}
Beispiel #6
0
/** 
 * Draw the Poisson estimate of the occupancy
 * 
 * @param filename Input file name 
 * @param folder   Input folder name in file
 * 
 * @deprecated Use QATrender instead
 * @ingroup pwglf_forward_scripts_qa
 */
void
DrawOccupancy(const char* filename="forward.root", 
	      const char* folder="ForwardResults")
{
  gStyle->SetPalette(1);
  gStyle->SetOptFit(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptTitle(0);
  gStyle->SetTitleW(.4);
  gStyle->SetTitleH(.1);
  gStyle->SetTitleX(.4);
  // gStyle->SetTitleY(.1);
  gStyle->SetTitleColor(0);
  gStyle->SetTitleStyle(0);
  gStyle->SetTitleBorderSize(0);
  
  TFile* file = TFile::Open(filename, "READ");
  if (!file) { 
    Error("DrawOccupancy", "failed to open %s", filename);
    return;
  }

  TList* forward = static_cast<TList*>(file->Get(folder));
  if (!forward) { 
    Error("DrawOccupancy", "List %s not found in %s", folder, filename);
    return;
  }

  TList* dc = static_cast<TList*>(forward->FindObject("fmdDensityCalculator"));
  if (!dc) { 
    Error("DrawOccupancy", "List fmdDensityCalculator not found in Forward");
    return;
  }
  
  TCanvas* c = new TCanvas("occupancy", 
			   "Mean Occupancy", 900, 700);
  c->SetFillColor(0);
  c->SetBorderSize(0);
  c->SetBorderMode(0);
  c->SetHighLightColor(0);
  c->SetBottomMargin(.15);
  c->SetTopMargin(.02);
  c->SetRightMargin(.02);
  c->SetLeftMargin(.15);
  c->Divide(3, 2, 0, 0);
  

  Double_t corrs[5];
  c->cd(1); corrs[0] = DrawRingOccupancy(dc, 1, 'I');
  c->cd(2); corrs[1] = DrawRingOccupancy(dc, 2, 'I');
  c->cd(5); corrs[2] = DrawRingOccupancy(dc, 2, 'O');
  c->cd(3); corrs[3] = DrawRingOccupancy(dc, 3, 'I');
  c->cd(6); corrs[4] = DrawRingOccupancy(dc, 3, 'O');

  TVirtualPad* p = c->cd(4);
  p->SetTopMargin(0.05);
  p->SetRightMargin(0.10);
  p->SetLeftMargin(0.15);
  p->SetBottomMargin(0.15);
  p->SetFillColor(0);

  TH1D* hc = new TH1D("occ", "Mean occupancy", 5, .5, 5.5);
  hc->SetFillColor(kRed+1);
  hc->SetFillStyle(3001);
  hc->SetMinimum(0.0);
  hc->GetXaxis()->SetBinLabel(1,"FMD1i"); hc->SetBinContent(1,corrs[0]);
  hc->GetXaxis()->SetBinLabel(2,"FMD2i"); hc->SetBinContent(2,corrs[1]);
  hc->GetXaxis()->SetBinLabel(3,"FMD2o"); hc->SetBinContent(3,corrs[2]);
  hc->GetXaxis()->SetBinLabel(4,"FMD3i"); hc->SetBinContent(4,corrs[3]);
  hc->GetXaxis()->SetBinLabel(5,"FMD3o"); hc->SetBinContent(5,corrs[4]);
  hc->GetXaxis()->SetLabelSize(0.08);
  hc->GetYaxis()->SetTitle("#bar{occupancy}");
  hc->SetMarkerSize(1.5);
  hc->Draw("text hist");
  hc->SetMaximum(hc->GetMaximum()*1.5);

  // TH2D* highCuts = static_cast<TH2D*>(dc->FindObject("highCuts"));
  // if (highCuts) highCuts->Draw("colz");
  c->cd();
  c->SaveAs("occupancy.png");
}
Beispiel #7
0
void plot(char* v, int run, int cut, TCanvas* cvs, int fit=0, int bin1=-1, int bin2=-1, float ymax=0.0, int rebin=0){   
    int bin0=1;
    char c[100];
    char c2[100];
    readfile(OPT,run);
    gStyle->SetOptStat(0);
    gStyle->SetOptFit(0);
    gStyle->SetOptTitle(0);
    cvs->Clear();
    int b1=bin1, b2=bin1+1, b3=bin2, b4=b3;
    if(bin1<0) {cvs->Divide(kNPtBin-bin0,kNPtBin-bin0); b1=bin0; b2=kNPtBin; b3=bin0;}
    float ptcut[kNPtBin+1]={0.5,1.0,1.5,2.0,2.5,3.0,10.0};
    memset(PAR,0,sizeof(PAR));
    TText* t;
    for(int i=b1; i<b2; i++){
	if(bin1<0) b4=i;
	for(int j=b3; j<=b4; j++){
	    int cc=cut;
	    if(cut==99 && (v=="m1" || v=="m2")) cc=0;
	    if(cut==99 && v=="dphi") cc=1;
	    TH1F *h,*h2,*h3,*h4;
	    TH2F *h2d;

	    //get normalizations
	    float norm0=1.0;
	    float norm1=1.0;
	    float norm2=1.0;
	    float norm3=1.0;
	    if(v=="m0" || v=="phi0"){}
	    else{
		sprintf(c,"m0_%1d_c%d",i,cc);
		TH1F* h0 = (TH1F*)mTFile->Get(c);
		norm0 = h0->GetEntries();
		sprintf(c,"m2_%1d%1d_c%d",i,j,cc);
		TH1F* h1 = (TH1F*)mTFile->Get(c);
		norm1 = h1->GetEntries();
		printf("n0=%d n1=%d\n",norm0,norm1);
		norm2=norm1/norm0;
		norm3=norm2/ZggCut;
	    }

	    int opt=1, log=0;
	    if(v=="mix"){
		h3=mix(run,cc,i,j,0,1,h,h2);
		h1->SetLineColor(1);
		h2->SetLineColor(6);
	    }else if(v=="corr"){
		h = mix(run,cc,i,j,0,1);
		if(rebin>0) h->Rebin(rebin);
		if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0);
		int nbin = h->GetNbinsX();
                h->Sumw2();
                if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);}
                else       {h->Scale(1.0/norm0*nbin/2.0/PI);}
	    }else if(v=="norm"){
		sprintf(c,"dphi_%1d%1d_c%d",i,j,cc);
                h = (TH1F*)mTFile->Get(c);
		if(rebin>0) h->Rebin(rebin);
		if(fit==1) h->GetXaxis()->SetRangeUser(PI/2.0,3.0*PI/2.0);
		int nbin = h->GetNbinsX();
		h->Sumw2();
		if(run<20) {h->Scale(1.0/norm0*nbin/2.0/PI/ZggCut);}
		else       {h->Scale(1.0/norm0*nbin/2.0/PI);}
	    }else if(v=="mall"){
		sprintf(c,"m0_%1d_c%d",i,0);
		sprintf(c2,"m0_%1d%1d_c%d",i,j,0);
		h4 = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2);
		float norm4 = h4->Integral(h4->GetXaxis()->FindBin(MassCut0),h4->GetXaxis()->FindBin(MassCut1));
		h4->Scale(norm1/norm4);
		h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2);
		sprintf(c,"m0_%1d_c%d",i,cc);
		sprintf(c2,"m0_%1d%1d_c%d",i,j,cc);
		h = (TH1F*)((TH1F*)mTFile->Get(c))->Clone(c2); h->SetLineColor(6);
		h->Scale(norm2); 
		sprintf(c,"m1_%1d%1d_c%d",i,j,cc);
                h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(2);
		sprintf(c,"m2_%1d%1d_c%d",i,j,cc); 
                h3 = (TH1F*)mTFile->Get(c); h3->SetLineColor(4);	   
	    }else if(v=="z12"){
		sprintf(c,"z1_%1d%1d_c%d",i,j,cc);
                h = (TH1F*)mTFile->Get(c); h->SetLineColor(2);
		sprintf(c,"z2_%1d%1d_c%d",i,j,cc); 
                h2 = (TH1F*)mTFile->Get(c); h2->SetLineColor(4);
	    }else if(v=="m0" || v=="phi0"){
		sprintf(c,"%s_%1d_c%d",v,i,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
	    }else if(v=="bbce"){
		opt=1;
		log=1;
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
		h->SetMinimum(0.1);
	    }else if(v=="phi1" || v=="phi2"){
		opt=1;
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
	    }else if(v=="phi1dphi"){
		opt=2;
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
	    }else{
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,cc);
		printf("%s\n",c);
		h = (TH1F*)mTFile->Get(c);		
	    }
	    if(bin1<0){
		TVirtualPad *pad = cvs->cd((i-bin0)*(kNPtBin-bin0)+(j-bin0)+1);
		pad->SetRightMargin(0.01);
		pad->SetLeftMargin(0);
		pad->SetTopMargin(0);
		pad->SetBottomMargin(0.01);
		pad->Draw();		
	    }
	    h->SetMinimum(0.0);
	    if(ymax>0.0) h->SetMaximum(ymax);
	    if(opt==0) h->Draw("e");
	    if(opt==1) h->Draw();
	    if(opt==2) h->Draw("colz");
	    if(v=="mall"){
		h4->Draw("same");
		h2->Draw("same");
		h3->Draw("same");
	    }
	    if(v=="z12" || v=="mix") h2->Draw("same");
	    TF1* f;
	    if((v=="norm" || v=="corr") && fit==1){
		f=new TF1("oneGaus",oneGaus,+PI/2.0,+PI*3.0/2.0,3);
		f->SetParameters(norm3/10.0,norm3/2.0,0.3);
		f->SetParNames("Const","IntFar","SigFar");
		f->SetParLimits(0,0.0,1.0);
		f->SetParLimits(1,0.0,1.0);
		f->SetParLimits(2,0.0,3.0);
		f->SetLineColor(2); f->SetLineWidth(1);
		h->Fit("oneGaus","Q");
		PAR[i][j][0]=f->GetParameter(0);
		PAR[i][j][1]=f->GetParameter(1);
		PAR[i][j][2]=f->GetParameter(2);
		printf("norm=%8.6f Int=%8.6f IntFar=%8.6 SigFar=%6.3f C=%8.6f\n",
		       norm3,PAR[i][j][1]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][2],PAR[i][j][0]);
	    }
	    if((v=="norm" || v="corr") && fit==2){
		f=new TF1("twoGaus",twoGaus,-PI/2.0,+PI*3.0/2.0,5);
		f->SetParameters(norm3/10.0,norm3/2.0,0.3,norm3/2.0,0.3);
		f->SetParNames("Const","IntNear","SigNear","IntFar","SigFar");
		f->SetParLimits(0,0.0,1.0);
		f->SetParLimits(1,0.0,1.0);
		f->SetParLimits(2,0.0,3.0);
		f->SetParLimits(3,0.0,1.0);
		f->SetParLimits(4,0.0,3.0);
		f->SetLineColor(2); f->SetLineWidth(1);
		h->Fit("twoGaus","Q");
		PAR[i][j][0]=f->GetParameter(0);
		PAR[i][j][1]=f->GetParameter(1);
		PAR[i][j][2]=f->GetParameter(2);
		PAR[i][j][3]=f->GetParameter(3);
		PAR[i][j][4]=f->GetParameter(4);
		printf("norm=%8.6f Int=%8.6f IntNear=%8.6f IntFar=%8.6f SigNear=%6.3f  SigFar=%6.3f C=%8.6f\n",
		       norm3,PAR[i][j][1]+PAR[i][j][3]+PAR[i][j][0],PAR[i][j][1],PAR[i][j][3],
		       PAR[i][j][2],PAR[i][j][4],PAR[i][j][0]);
	    }

	    float xx=0.60, yy=0.85, dy=0.04, size=0.04;
	    if(bin1<0){xx=0.45, yy=0.90, dy=0.08, size=0.08;}
	    if(v=="z12") {xx=0.1; yy=0.35;}
	    t = new TText(xx, yy,    Form("pT1=%3.1f-%3.1f",ptcut[i],ptcut[i+1])); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    t = new TText(xx, yy-dy, Form("pT2=%3.1f-%3.1f",ptcut[j],ptcut[j+1])); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    if(norm3>0.0){
		t = new TText(xx, yy-dy*2, Form("P=%7.5f",norm3)); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    }
	    if((v=="norm" || v="corr")  && fit==1){
		t = new TText(xx, yy-dy*3, Form("PBg=%7.5f",  PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*5, Form("Saway=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    }
	    if((v=="norm" || v="corr")  && fit==2){
		t = new TText(xx, yy-dy*3, Form("Pnear=%7.5f",PAR[i][j][1])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*4, Form("Paway=%7.5f",PAR[i][j][3])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*5, Form("PBg=%7.5f",  PAR[i][j][0])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*6, Form("Snear=%4.2f",PAR[i][j][2])); t->SetNDC(); t->SetTextSize(size); t->Draw();
		t = new TText(xx, yy-dy*7, Form("Saway=%4.2f",PAR[i][j][4])); t->SetNDC(); t->SetTextSize(size); t->Draw();
	    }
	    if(cut==88) h->SetLineColor(2);
	    if(cut==99 && (v=="m1"|| v=="m2")){
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,1);
		h = (TH1F*)mTFile->Get(c);
		h->SetLineColor(4);
		h->Draw("same");
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,2);
		h = (TH1F*)mTFile->Get(c);
		h->SetLineColor(2);
		h->Draw("same");
	    }
	    if(cut==99 && v=="dphi"){
		h->SetLineColor(4);
		sprintf(c,"%s_%1d%1d_c%d",v,i,j,2);
                h = (TH1F*)mTFile->Get(c);
                h->SetLineColor(2);
                h->Draw("same");		
	    }
	    if(bin1>0){
		t = new TText(0.1, 0.92,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.07); t->SetTextColor(1); t->Draw();
		if     (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d_bin%d%d.png",v,cut,i,j);}
		else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d_bin%d%d.png",v,cut,i,j);}
		else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d_bin%d%d.png",v,cut,i,j);}
		else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d_bin%d%d.png",v,cut,i,j);}
		else                       {sprintf(c,"plot/dipi0_%d_%s_c%d_bin%d%d.png",run,v,cut,i,j);}
		printf("Saving %s\n",c);
		cvs->SaveAs(c);	       
	    }
	}
    }
    if(bin1<0){
	cvs->cd(2);
	t = new TText(0.0, 0.85,Form("%s %s",CBEAM,CCUT[cut])); t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(1); t->Draw();
    }
    if(v=="mall"){
	t = new TText(0.05, 0.65,"M1(no mass, scaled)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(1); t->Draw();
	t = new TText(0.05, 0.55,"M1(without M2)/P"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(6); t->Draw();
	t = new TText(0.05, 0.45,"M1(with M2)"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw();
	t = new TText(0.05, 0.35,"M2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw();
    }
    if(v=="z12"){
	t = new TText(0.05, 0.65,"Zgg1"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(2); t->Draw();
	t = new TText(0.05, 0.55,"Zgg2"); t->SetNDC(); t->SetTextSize(0.10); t->SetTextColor(4); t->Draw();
    }
    if(cut==99) {
	t = new TText(0.0, 0.65, "Inclusive Pair");  t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(4); t->Draw();
	t = new TText(0.0, 0.45, "Exclusive Pair");  t->SetNDC(); t->SetTextSize(0.12); t->SetTextColor(2); t->Draw();
    }
    if(bin1<0){
	if     (run==1 || run==11) {sprintf(c,"plot/dipi0_pp_%s_c%d.png",v,cut);}
	else if(run==5 || run==15) {sprintf(c,"plot/dipi0_pau1_%s_c%d.png",v,cut);}
	else if(run==2 || run==12) {sprintf(c,"plot/dipi0_pau2_%s_c%d.png",v,cut);}
	else if(run==3 || run==13) {sprintf(c,"plot/dipi0_pal_%s_c%d.png",v,cut);}
	else                       {sprintf(c,"plot/dipi0_%d_%s_c%d.png",run,v,cut);}
	printf("Saving %s\n",c);
	cvs->SaveAs(c);
    }
}
Beispiel #8
0
void make_v2_graphs(const char* output = "v2_inputs.root")
{
  TFile* fout = new TFile(output,"recreate");
  fout->cd();
  TGraphErrors* trig_inc_v2[4];  TGraphErrors* trig_inc_sys[4];
  TGraphErrors* trig_dec_v2[4];  TGraphErrors* trig_dec_sys[4];
  TGraphErrors* trig_pi0_v2[4];  TGraphErrors* trig_pi0_sys[4];
  TGraphErrors* hassoc_v2[4];  TGraphErrors* hassoc_sys[4];
  
  //[centrality][pt]
  double inc_v2[4][4]; double inc_v2_err[4][4]; double inc_v2_sys[4][4];
  double dec_v2[4][4]; double dec_v2_err[4][4]; double dec_v2_sys[4][4];
  double pi0_v2[4][4]; double pi0_v2_err[4][4]; double pi0_v2_sys[4][4];
  double hadron_v2[4][5]; double hadron_v2_err[4][5]; double hadron_v2_sys[4][5];

  inc_v2[0][0] = 0.0423226; inc_v2_err[0][0] = 0.00175307; inc_v2_sys[0][0] = 0.0076029;
  inc_v2[1][0] = 0.0852710; inc_v2_err[1][0] = 0.00207489; inc_v2_sys[1][0] = 0.0179611;
  inc_v2[2][0] = 0.1379880; inc_v2_err[2][0] = 0.00432101; inc_v2_sys[2][0] = 0.0183026;
  inc_v2[3][0] = 0.4418120; inc_v2_err[3][0] = 0.01932520; inc_v2_sys[3][0] = 0.0197302;

  inc_v2[0][1] = 0.0461296; inc_v2_err[0][1] = 0.00454517; inc_v2_sys[0][1] = 0.00432369;
  inc_v2[1][1] = 0.0738878; inc_v2_err[1][1] = 0.00558803; inc_v2_sys[1][1] = 0.01509860;
  inc_v2[2][1] = 0.1432810; inc_v2_err[2][1] = 0.01209420; inc_v2_sys[2][1] = 0.01267580;
  inc_v2[3][1] = 0.5100750; inc_v2_err[3][1] = 0.05529200; inc_v2_sys[3][1] = 0.04872020;

  inc_v2[0][2] = 0.0398415; inc_v2_err[0][2] = 0.00836215; inc_v2_sys[0][2] = 0.00344175;
  inc_v2[1][2] = 0.0520371; inc_v2_err[1][2] = 0.01062420; inc_v2_sys[1][2] = 0.02247170;
  inc_v2[2][2] = 0.1245420; inc_v2_err[2][2] = 0.02340030; inc_v2_sys[2][2] = 0.01237760;
  inc_v2[3][2] = 0.4952110; inc_v2_err[3][2] = 0.11218300; inc_v2_sys[3][2] = 0.15661100;

  inc_v2[0][3] = 0.0169588; inc_v2_err[0][3] = 0.0189458; inc_v2_sys[0][3] = 0.00465717;
  inc_v2[1][3] = 0.0644017; inc_v2_err[1][3] = 0.0252076; inc_v2_sys[1][3] = 0.02599590;
  inc_v2[2][3] = 0.0260897; inc_v2_err[2][3] = 0.0570124; inc_v2_sys[2][3] = 0.05901420;
  inc_v2[3][3] = -0.299766; inc_v2_err[3][3] = 0.2958920; inc_v2_sys[3][3] = 0.79791400;

  pi0_v2[0][0] = 0.0835297; pi0_v2_err[0][0] = 0.00287215; pi0_v2_sys[0][0] = 0.0118235;
  pi0_v2[1][0] = 0.1335370; pi0_v2_err[1][0] = 0.00330527; pi0_v2_sys[1][0] = 0.0229443;
  pi0_v2[2][0] = 0.1744460; pi0_v2_err[2][0] = 0.00671865; pi0_v2_sys[2][0] = 0.0244753;
  pi0_v2[3][0] = 0.4214010; pi0_v2_err[3][0] = 0.02954310; pi0_v2_sys[3][0] = 0.0485074;

  pi0_v2[0][1] = 0.0755782; pi0_v2_err[0][1] = 0.00531345; pi0_v2_sys[0][1] = 0.00960588;
  pi0_v2[1][1] = 0.1162020; pi0_v2_err[1][1] = 0.00587208; pi0_v2_sys[1][1] = 0.02417620;
  pi0_v2[2][1] = 0.1548150; pi0_v2_err[2][1] = 0.01164770; pi0_v2_sys[2][1] = 0.01545110;
  pi0_v2[3][1] = 0.5469130; pi0_v2_err[3][1] = 0.05027790; pi0_v2_sys[3][1] = 0.03882330;

  pi0_v2[0][2] = 0.0839048; pi0_v2_err[0][2] = 0.01013930; pi0_v2_sys[0][2] = 0.01805810;
  pi0_v2[1][2] = 0.1030550; pi0_v2_err[1][2] = 0.01122400; pi0_v2_sys[1][2] = 0.03859360;
  pi0_v2[2][2] = 0.0801250; pi0_v2_err[2][2] = 0.05710570; pi0_v2_sys[2][2] = 0.02456170;
  pi0_v2[3][2] = 0.5638220; pi0_v2_err[3][2] = 0.10233000; pi0_v2_sys[3][2] = 0.02597060;

  pi0_v2[0][3] = 0.1055550; pi0_v2_err[0][3] = 0.0258798; pi0_v2_sys[0][3] = 0.04751440;
  pi0_v2[1][3] = 0.0861201; pi0_v2_err[1][3] = 0.0290550; pi0_v2_sys[1][3] = 0.02462110;
  pi0_v2[2][3] = 0.1169110; pi0_v2_err[2][3] = 0.0579355; pi0_v2_sys[2][3] = 0.06628670;
  pi0_v2[3][3] = 0.4231040; pi0_v2_err[3][3] = 0.3135600; pi0_v2_sys[3][3] = 0.25851400;

  dec_v2[0][0] = 0.0802729; dec_v2_err[0][0] = 0.00259655; dec_v2_sys[0][0] = 0.0106477;
  dec_v2[1][0] = 0.1270690; dec_v2_err[1][0] = 0.00292113; dec_v2_sys[1][0] = 0.0236515;
  dec_v2[2][0] = 0.1708000; dec_v2_err[2][0] = 0.00588472; dec_v2_sys[2][0] = 0.0221000;
  dec_v2[3][0] = 0.4716660; dec_v2_err[3][0] = 0.02824160; dec_v2_sys[3][0] = 0.0515539;

  dec_v2[0][1] = 0.0769908; dec_v2_err[0][1] = 0.00440387; dec_v2_sys[0][1] = 0.01112830;
  dec_v2[1][1] = 0.1142120; dec_v2_err[1][1] = 0.00505774; dec_v2_sys[1][1] = 0.02610160;
  dec_v2[2][1] = 0.1723320; dec_v2_err[2][1] = 0.01048860; dec_v2_sys[2][1] = 0.01933210;
  dec_v2[3][1] = 0.5762520; dec_v2_err[3][1] = 0.05424370; dec_v2_sys[3][1] = 0.04244810;

  //testing old v2 because 9-12 seems high
  //v2[2][2] = 0.242351; err_v2_pi0[2][2] = 0.0226531; sys_err_v2_pi0[2][2] = 0.0129369;
  dec_v2[0][2] = 0.0831338; dec_v2_err[0][2] = 0.00951379; dec_v2_sys[0][2] = 0.02080890;
  dec_v2[1][2] = 0.1005180; dec_v2_err[1][2] = 0.01043080; dec_v2_sys[1][2] = 0.03353270;
  dec_v2[2][2] = 0.2019460; dec_v2_err[2][2] = 0.02221120; dec_v2_sys[2][2] = 0.01217420;
  dec_v2[3][2] = 0.5698930; dec_v2_err[3][2] = 0.11125100; dec_v2_sys[3][2] = 0.03953840;

  dec_v2[0][3] = 0.1026670; dec_v2_err[0][3] = 0.0238731; dec_v2_sys[0][3] = 0.03616490;
  dec_v2[1][3] = 0.0893677; dec_v2_err[1][3] = 0.0271222; dec_v2_sys[1][3] = 0.03356940;
  dec_v2[2][3] = 0.1307690; dec_v2_err[2][3] = 0.0609939; dec_v2_sys[2][3] = 0.07152490;
  dec_v2[3][3] = 0.3373860; dec_v2_err[3][3] = 0.2751690; dec_v2_sys[3][3] = 0.37330200;

  hadron_v2[0][4]=0.0440219; hadron_v2_err[0][4]=0.000145508; hadron_v2_sys[0][4]=0.00137609;
  hadron_v2[1][4]=0.0826719; hadron_v2_err[1][4]=0.000171826; hadron_v2_sys[1][4]=0.00296920;
  hadron_v2[2][4]=0.0980676; hadron_v2_err[2][4]=0.000408317; hadron_v2_sys[2][4]=0.00221491;
  hadron_v2[3][4]=0.0868451; hadron_v2_err[3][4]=0.001215900; hadron_v2_sys[3][4]=0.00435710;

  hadron_v2[0][0]=0.0745276; hadron_v2_err[0][0]=7.62922e-05; hadron_v2_sys[0][0]=0.00202200;
  hadron_v2[1][0]=0.1381520; hadron_v2_err[1][0]=8.20737e-05; hadron_v2_sys[1][0]=0.00419830;
  hadron_v2[2][0]=0.1646640; hadron_v2_err[2][0]=0.000219383; hadron_v2_sys[2][0]=0.00260620;
  hadron_v2[3][0]=0.1693740; hadron_v2_err[3][0]=0.001336240; hadron_v2_sys[3][0]=0.00693613;

  hadron_v2[0][1]=0.1095070; hadron_v2_err[0][1]=0.000216781; hadron_v2_sys[0][1]=0.00307190;
  hadron_v2[1][1]=0.1933760; hadron_v2_err[1][1]=0.000249992; hadron_v2_sys[1][1]=0.00579030;
  hadron_v2[2][1]=0.2177190; hadron_v2_err[2][1]=0.000623148; hadron_v2_sys[2][1]=0.00315090;
  hadron_v2[3][1]=0.2150790; hadron_v2_err[3][1]=0.003462490; hadron_v2_sys[3][1]=0.00682347;

  hadron_v2[0][2]=0.1103720; hadron_v2_err[0][2]=0.000591522; hadron_v2_sys[0][2]=0.00322900;
  hadron_v2[1][2]=0.1907190; hadron_v2_err[1][2]=0.000680041; hadron_v2_sys[1][2]=0.00616680;
  hadron_v2[2][2]=0.2077700; hadron_v2_err[2][2]=0.001614320; hadron_v2_sys[2][2]=0.00375637;
  hadron_v2[3][2]=0.2052480; hadron_v2_err[3][2]=0.008518280; hadron_v2_sys[3][2]=0.01208620;

  hadron_v2[0][3]=0.0827500; hadron_v2_err[0][3]=0.00844; hadron_v2_sys[0][3]=0.00500;
  hadron_v2[1][3]=0.1297000; hadron_v2_err[1][3]=0.01350; hadron_v2_sys[1][3]=0.00830;
  hadron_v2[2][3]=0.1718000; hadron_v2_err[2][3]=0.01718; hadron_v2_sys[2][3]=0.00858;
  hadron_v2[3][3]=0.2052480; hadron_v2_err[3][3]=8.52e-4; hadron_v2_sys[3][3]=0.05*hadron_v2[3][4];

  double pt_trig[4] = {5.5,7.5,9.5,12.5};
  double pt_trig_err[4] = {0,0,0,0};
  double pt_assoc[5] = {0.6,1.3,2.3,3.5,5.5};
  double pt_assoc_err[5] = {0,0,0,0,0};
  std::ostringstream name;
  for( int i = 0; i < 4; i++ )
  {
    name.str("");
    name << "gamma_inc_v2_" << i;
    trig_inc_v2[i] = new TGraphErrors(4,pt_trig,inc_v2[i],pt_trig_err,inc_v2_err[i]);
    trig_inc_v2[i]->SetName(name.str().c_str());
    trig_inc_v2[i]->SetTitle(name.str().c_str());
    trig_inc_v2[i]->Write();

    name.str("");
    name << "gamma_inc_v2sys_" << i;
    trig_inc_sys[i] = new TGraphErrors(4,pt_trig,inc_v2[i],pt_trig_err,inc_v2_sys[i]);
    trig_inc_sys[i]->SetName(name.str().c_str());
    trig_inc_sys[i]->SetTitle(name.str().c_str());
    trig_inc_sys[i]->Write();

    name.str("");
    name << "gamma_dec_v2_" << i;
    trig_dec_v2[i] = new TGraphErrors(4,pt_trig,dec_v2[i],pt_trig_err,dec_v2_err[i]);
    trig_dec_v2[i]->SetName(name.str().c_str());
    trig_dec_v2[i]->SetTitle(name.str().c_str());
    trig_dec_v2[i]->Write();
 
    name.str("");
    name << "gamma_dec_v2sys_" << i;
    trig_dec_sys[i] = new TGraphErrors(4,pt_trig,dec_v2[i],pt_trig_err,dec_v2_sys[i]);
    trig_dec_sys[i]->SetName(name.str().c_str());
    trig_dec_sys[i]->SetTitle(name.str().c_str());
    trig_dec_sys[i]->Write();
 
    name.str("");
    name << "pi0_v2_" << i;
    trig_pi0_v2[i] = new TGraphErrors(4,pt_trig,pi0_v2[i],pt_trig_err,pi0_v2_err[i]);
    trig_pi0_v2[i]->SetName(name.str().c_str());
    trig_pi0_v2[i]->SetTitle(name.str().c_str());
    trig_pi0_v2[i]->Write();

    name.str("");
    name << "pi0_v2sys_" << i;
    trig_pi0_sys[i] = new TGraphErrors(4,pt_trig,pi0_v2[i],pt_trig_err,pi0_v2_sys[i]);
    trig_pi0_sys[i]->SetName(name.str().c_str());
    trig_pi0_sys[i]->SetTitle(name.str().c_str());
    trig_pi0_sys[i]->Write();

    name.str("");
    name << "hadron_v2_" << i;
    hassoc_v2[i] = new TGraphErrors(5,pt_assoc,hadron_v2[i],pt_assoc_err,hadron_v2_err[i]);
    hassoc_v2[i]->SetName(name.str().c_str());
    hassoc_v2[i]->SetTitle(name.str().c_str());
    hassoc_v2[i]->Write();

    name.str("");
    name << "hadron_v2sys_" << i;
    hassoc_sys[i] = new TGraphErrors(5,pt_assoc,hadron_v2[i],pt_assoc_err,hadron_v2_sys[i]);
    hassoc_sys[i]->SetName(name.str().c_str());
    hassoc_sys[i]->SetTitle(name.str().c_str());
    hassoc_sys[i]->Write();

  }

  int cent[5] = {0,20,40,60,90};
  int color[4] = {kBlack,kRed,kBlue,kViolet-7};
  int sys_color[4] = {kGray,kRed-9,kBlue-9,kViolet-9};
  TCanvas* can = new TCanvas("can","can");
  can->Divide(2,2,0.001,0.001);
  TH1D* thisto = new TH1D("thisto",";p^{#gamma}_{T}   ;v_{2}   ",100,0.0,15.0);
  thisto->SetAxisRange(0.0,0.75,"Y");
  thisto->SetAxisRange(4.5,14.0,"X");
  TH1D* ahisto = new TH1D("ahisto",";p^{h}_{T}    ;v_{2}   ",100,0.0,15.0);
  ahisto->SetAxisRange(0.0,0.75,"Y");
  ahisto->SetAxisRange(0.0,6.0,"X");
  for( int i = 0; i < 4; i++ )
  {
    TVirtualPad* pad = can->cd(i+1);
    pad->SetRightMargin(0.01);
    pad->SetTopMargin(0.01);
    if( i < 3 ) thisto->Draw();
    else ahisto->Draw();
  }
  TLegend* leg = new TLegend(0.5,0.5,0.9,0.9);
  leg->SetBorderSize(0);
  leg->SetFillColor(0);
  for( int ic = 0; ic < 4; ic++ )
  {
    can->cd(1);
    trig_inc_sys[ic]->SetMarkerSize(0);
    trig_inc_sys[ic]->SetLineWidth(10);
    trig_inc_sys[ic]->SetLineColor(sys_color[ic]);
    trig_inc_sys[ic]->Draw("E1,Psame");
    trig_inc_v2[ic]->SetMarkerColor(color[ic]);
    trig_inc_v2[ic]->SetLineColor(color[ic]);
    trig_inc_v2[ic]->Draw("Psame");
    // trig_inc_v2[ic]->Write();
    // trig_inc_sys[ic]->Write();
    can->cd(2);
    trig_dec_sys[ic]->SetMarkerSize(0);
    trig_dec_sys[ic]->SetLineWidth(10);
    trig_dec_sys[ic]->SetLineColor(sys_color[ic]);
    trig_dec_sys[ic]->Draw("E1,Psame");
    trig_dec_v2[ic]->SetMarkerColor(color[ic]);
    trig_dec_v2[ic]->SetLineColor(color[ic]);
    trig_dec_v2[ic]->Draw("Psame");
    can->cd(3);
    trig_pi0_sys[ic]->SetMarkerSize(0);
    trig_pi0_sys[ic]->SetLineWidth(10);
    trig_pi0_sys[ic]->SetLineColor(sys_color[ic]);
    trig_pi0_sys[ic]->Draw("E1,Psame");
    trig_pi0_v2[ic]->SetMarkerColor(color[ic]);
    trig_pi0_v2[ic]->SetLineColor(color[ic]);
    trig_pi0_v2[ic]->Draw("Psame");
    can->cd(4);
    hassoc_sys[ic]->SetMarkerSize(0);
    hassoc_sys[ic]->SetLineWidth(10);
    hassoc_sys[ic]->SetLineColor(sys_color[ic]);
    hassoc_sys[ic]->Draw("E1,Psame");
    hassoc_v2[ic]->SetMarkerColor(color[ic]);
    hassoc_v2[ic]->SetLineColor(color[ic]);
    hassoc_v2[ic]->Draw("Psame");
    name.str("");
    name << cent[ic] << " - " << cent[ic+1] << "%";
    leg->AddEntry(trig_inc_v2[ic],name.str().c_str(),"P");
  }
  leg->Draw();
  can->Write();
}
void EstimateBg_76X(bool save=0, std::string in = "",
		std::string out = "/afs/cern.ch/user/j/jkarancs/public/NOTES/notes/AN-14-290/trunk/Plots/v1.0/", std::string ext="png") {
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  
  bool latex = save;
  
  bool ABCD_prime = 0;
  bool TT_only = 0;
  
  std::stringstream ss, ss2;
  ss<<DPHI_CUT; ss2<<R_CUT;
  std::string dphi_cut = ss.str().replace(ss.str().find("."),1,"p");
  std::string r_cut = ss2.str().replace(ss2.str().find("."),1,"p");
  
  std::string filename = in.size() ? in : 
    //"results/Plotter_out_2016_05_31_08h48m57_replot.root";
    "results/Plotter_out_2016_06_24_14h28m51.root";
  
  std::vector<std::string> samples[4];
  //samples[0].push_back("TTJetsMGHT");
  //samples[0].push_back("TTJetsMG");
  //samples[0].push_back("TTJetsNLOFXFX");
  //samples[0].push_back("TTNLO");
  //samples[0].push_back("TTNLOHerwig");
  //samples[0].push_back("TTPowheg");
  //samples[0].push_back("TTPowhegmpiOff");
  //samples[0].push_back("TTPowhegnoCR");
  //samples[0].push_back("TTPowhegHerwig");
  
  //+data+ samples[1].push_back("SingleElectron");
  //+data+ samples[1].push_back("SingleMuon");
  if (TT_only) {
    samples[1].push_back("TTJetsMGHT");
    samples[1].push_back("TTJetsMG");
    samples[1].push_back("TTJetsNLOFXFX");
    samples[1].push_back("TTNLO");
    samples[1].push_back("TTNLOHerwig");
    samples[1].push_back("TTPowheg");
    samples[1].push_back("TTPowhegmpiOFF");
    samples[1].push_back("TTPowhegnoCR");
    samples[1].push_back("TTPowhegHerwig");
  } else {
    samples[1].push_back("TTJetsMGHT");
    //samples[1].push_back("TTJetsMG");
    //samples[1].push_back("TTJetsNLOFXFX");
    //samples[1].push_back("TTNLO");
    //samples[1].push_back("TTNLOHerwig");
    //samples[1].push_back("TTPowheg");
    //samples[1].push_back("TTPowhegmpiOff");
    //samples[1].push_back("TTPowhegnoCR");
    //samples[1].push_back("TTPowhegHerwig");
    samples[1].push_back("ZJets");
    samples[1].push_back("TTX");
    samples[1].push_back("WJets");
    samples[1].push_back("Diboson");
    samples[1].push_back("Top");
    samples[1].push_back("QCD");
    //ZERO samples[1].push_back("TZQ");
    //ZERO samples[1].push_back("ZJetsToQQ"); // Also WJetsToQQ
    //ZERO samples[1].push_back("GJets");
  }
  //samples[1].push_back("Data");
  // NTop Sideband All background summed
  samples[2].push_back("All Bkg.");
    
  // Signal in NTop bins
  samples[3].push_back("T1tttt");
  
  bool baderror = false;
  double weight[] = { 0.32686, 0.0505037, 0.00921411, 6.80717, 0.354934, 0.00484915 };
  int rebin = /*(R_CUT*10-int(R_CUT*10))==0 ? 10 :*/ (R_CUT*20-int(R_CUT*20))==0 ? 5 : (R_CUT*50-int(R_CUT*50))==0 ? 2 : 1;
  double sideband_fit_low_range[] = { 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15 };
  
  int i_h_side[]   = { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  int i_h_signal[] = { 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
  
  double scale_factors[] = { 1, 1, 1, 1, 1, 1, 1}; // All normal
  //double scale_factors[] = { /* TT */ 1, /* W */ 1, /* Z */ 1, /* T */ 1, /* TTV */ 1, /* QCD */ 2, /* VV */ 1 }; // QCD high
  //double scale_factors[] = { /* TT */ 5, /* W */ 1, /* Z */ 1, /* T */ 1, /* TTV */ 5, /* QCD */ 1, /* VV */ 1 }; // TT/TTV high
  //double scale_factors[] = { /* TT */ 1, /* W */ 2, /* Z */ 2, /* T */ 2, /* TTV */ 1, /* QCD */ 1, /* VV */ 2 }; // T/V/VV high
  
  Double_t Rranges_ABCD[][4] = 
    { { DPHI_CUT, 3.2, 0.0, DPHI_CUT  },
      { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 },
      { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 },
      { R_CUT_LOW-1e-10, R_CUT, R_CUT-1e-10, 1.20 } };
  bool doFitting = false;
  double sum_a = 0, sum_b = 0, sum_c = 0, sum_d = 0, sum_d_abcd = 0, sum_d_nevt = 0;
  double sum_a_err = 0, sum_b_err = 0, sum_c_err = 0, sum_d_err = 0, sum_d_abcd_err = 0;
  double sum_b_fit = 0, sum_d_fit = 0, sum_d_fit_comb = 0;
  double sum_b_fit_err = 0, sum_d_fit_err = 0, sum_d_fit_comb_err = 0;
  double comb_d = 0, comb_d_err = 0, comb_d_abcd = 0, comb_d_abcd_err = 0;
  if (latex) {
    printf("\\begin{table*}[htbH]\n");
    printf("\\small\n");
    printf("\\begin{center}\n");
    printf("\\topcaption{Estimated Standard Model background yields in ABCD regions. A, B is in the sideband, C and D is the signal band, D is the signal region.\\label{tab:SMBkgEstimate}}\n");
    printf("\\begin{tabular}{lrrrrrrrr}\n");
  }
  TFile *f = TFile::Open(filename.c_str());
  for (size_t iMethod = 0; iMethod<4; ++iMethod) if (!(iMethod==0&&samples[0].size()==0)){
    // Print Top row for each method
    if (latex) {
      if (iMethod==0) {
        printf("\\hline\n");
        printf("Method 2 & A & B & C & D = B*C/A & D obs. & Ratio pred./obs. & Pull & KS test\\\\\n");
      }	else if (iMethod==1){
        printf("\\hline\n");
        printf("Method 1 & A & B & C & D = B*C/A & D obs. & Ratio pred./obs. & Pull & KS test\\\\\n");
      }
      printf("\\hline\n");
    } else {
      std::stringstream r_sb_cut;
      if (R_CUT_LOW==0) r_sb_cut<<"R<"<<R_CUT;
      else r_sb_cut<<R_CUT_LOW<<"<R<"<<R_CUT;
      const char* prime = ABCD_prime ? "'" : "";
      //if (iMethod==0) printf("| *Sample* | *A (DPhi>2.8, SB)* | *B (DPhi<2.8, SB)* | *C (DPhi>2.8, Sig.B.)* | - | *D = B*C/A pred.* | *D (DPhi<2.8, Sig.B.) obs.* | *Ratio pred./obs.* |\n");
      //else if (iMethod==1) printf("| *Sample* | *A (R<%1.1f, SB)* | *B (R>%1.1f, SB)* | *C (R<%1.1f, Sig.B.)* | *D = B (R fit, SB) * C/A pred.* | *D = B*C/A pred.* | *D (R>%1.1f, Sig.B.) obs.* | *Ratio pred./obs.* | \n", R_CUT, R_CUT, R_CUT, R_CUT);
      if (iMethod==0) printf("| *Sample* | *A (DPhi>%1.1f, %s)* | *B (DPhi<%1.1f, %s)* | *C (DPhi>%1.1f, R>0.4)* | *D = B*C/A pred.* | *D (DPhi<%1.1f, R>0.4) obs.* | *Ratio pred./obs.* | *Pull (pred-obs)/error* | *KS test* |\n", DPHI_CUT, r_sb_cut.str().c_str(), DPHI_CUT, r_sb_cut.str().c_str(), DPHI_CUT, DPHI_CUT);
      else if (iMethod==1) printf("| *Sample* | *A%s (%s, <2 tag)* | *B%s (R>%1.1f, <2 tag)* | *C%s (%s, 2 tag)* | *D%s = B%s*C%s/A%s pred.* | *D%s (R>%1.1f, 2 tag) obs.* | *Ratio pred./obs.* | *Pull (pred-obs)/error* | *KS test* |\n", prime, r_sb_cut.str().c_str(), prime, R_CUT, prime, r_sb_cut.str().c_str(), prime, prime, prime, prime, prime, R_CUT);
    }
    TH1D *h_side_sum, *h_signal_sum;
    for (size_t iSample = 0; iSample<samples[iMethod].size(); ++iSample)  {
      std::string canname = 
	iMethod==0 ? std::string("DPhiBins")+(ABCD_prime ? "/RBins_0To1HadTop_" : "/RBins_2HadTop_")+samples[iMethod][iSample] :
	iMethod==1 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_"+samples[iMethod][iSample] :
	iMethod==2 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_Background" :
	iMethod==3 ? std::string("RFine/Tau32Cuts_")+(ABCD_prime ? "Fail" : "Pass")+"DPhiCut_"+samples[iMethod][iSample] : "";
      TCanvas *can = (TCanvas*)(f->Get(canname.c_str()));
      can = (TCanvas*)can->Clone();
      can->Draw();
      TH1D *h_side = (TH1D*)can->GetListOfPrimitives()->At(i_h_side[iMethod]);
      TH1D *h_signal = (TH1D*)can->GetListOfPrimitives()->At(i_h_signal[iMethod]);
      // Simulate different cross section by scaling a certain background
      if (iMethod==1) {
        TH1D *h_side_temp_scaled = (TH1D*)h_side->Clone(); h_side_temp_scaled->Scale(scale_factors[iSample]);
        TH1D *h_signal_temp_scaled = (TH1D*)h_signal->Clone(); h_signal_temp_scaled->Scale(scale_factors[iSample]);
        if (iSample==0) {
          h_side_sum = h_side_temp_scaled;
          h_signal_sum = h_signal_temp_scaled;
        } else {
          h_side_sum->Add(h_side_temp_scaled);
          h_signal_sum->Add(h_signal_temp_scaled);
        }
      } else if (iMethod==2) {
        h_side = h_side_sum;
        h_signal = h_signal_sum;
      }
      TH1D *h_pred =(TH1D*)h_side->Clone();
      if (iMethod!=0&&rebin>1) { h_side->Rebin(rebin); h_signal->Rebin(rebin); h_pred->Rebin(rebin); }
      TLegend *leg = (TLegend*)can->GetListOfPrimitives()->At(can->GetListOfPrimitives()->GetEntries()-1);
      leg->SetX1(0.35); leg->SetX2(0.65); leg->SetY1(0.6);
      
      // Add ratio plot
      int y1 = 350;
      int y2 = 150;
      int mid2 = 10;
      can->Divide(1,2);
      // Pad 1 (80+500+20 x 40+500)
      TVirtualPad* p = can->cd(1);
      p->SetPad(0,(y2+60+mid2)/(y1+y2+100.0+mid2),1,1);
      p->SetTopMargin(40.0/(y1+40));
      p->SetBottomMargin(0);
      p->SetRightMargin(0.05);
      p->SetLogy(1);
      h_side->GetYaxis()->SetRangeUser(1.00001e-4,1e4);
      h_side->Draw("HIST");
      h_signal->Draw("SAMEHISTE1");
      leg->Draw();
      // Pad 2 (80+500+20 x 200+60)
      p = can->cd(2);
      p->SetGrid(0,1);
      p->SetPad(0,0,1,(y2+60+mid2)/(y1+y2+100.0+mid2));
      p->SetTopMargin(((float)mid2)/(y2+60+mid2));
      p->SetBottomMargin(60.0/(y2+60+mid2));
      p->SetRightMargin(0.05);
      TH1D* ratio = (TH1D*)h_signal->Clone();
      TH1D* div = (TH1D*)h_side->Clone();
      //ratio->Scale(1/ratio->GetSumOfWeights());
      double sum_bins_ratio = iMethod==0 ? ratio->Integral():
	ratio->Integral(ratio->FindBin(R_CUT_LOW),ratio->FindBin(Rranges_ABCD[iMethod][3]));
      ratio->Scale(1/sum_bins_ratio);
      ratio->SetTitleSize(32.0/(y2+60+mid2),"xyz");
      ratio->SetLabelSize(20.0/(y2+60+mid2),"xyz");
      //ratio->Scale(1/div->GetSumOfWeights());
      double sum_bins_div = iMethod==0 ? div->Integral():
	div->Integral(div->FindBin(R_CUT_LOW),div->FindBin(Rranges_ABCD[iMethod][3]));
      div->Scale(1/sum_bins_div);
      ratio->Divide(div);
      //ratio->GetYaxis()->SetRangeUser(0,2);
      ratio->GetXaxis()->SetTitleOffset(0.7);
      ratio->GetYaxis()->SetNdivisions(305);
      ratio->GetYaxis()->SetTitle("Ratio (Norm.)");
      ratio->GetYaxis()->SetTitleOffset(0.4);
      ratio->SetTitleSize(24.0/(y2+60+mid2),"y");
      ratio->SetTitle("");
      ratio->SetMarkerStyle(20);
      ratio->SetMarkerColor(1);
      ratio->SetLineColor(1);
      ratio->GetYaxis()->SetRangeUser(0,4);
      ratio->Draw("PE1");
      TLine* l = new TLine(ratio->GetXaxis()->GetXmin(), 1, ratio->GetXaxis()->GetXmax(), 1);
      l->SetLineWidth(2);
      //l->SetLineColor(2);
      l->SetLineStyle(2);
      l->Draw();
      gPad->Update();
      // Fit ratio
      //TF1 *fit_ratio;
      //if (iMethod==1) {
      //  fit_ratio = new TF1("fit_ratio","pol0", Rranges_ABCD[iMethod][0], Rranges_ABCD[iMethod][1]);
      //  fit_ratio->SetLineColor(1);
      //  ratio->Fit("fit_ratio","RE");
      //  fit_ratio->SetRange(Rranges_ABCD[iMethod][0], Rranges_ABCD[iMethod][2]);
      //  fit_ratio->Draw("SAME");
      //}
      p = can->cd(1);
      
      // calculate integrals
      double integral[2][2] = { { 0, 0 }, { 0, 0 } };
      double integral_error[2][2] = { { 0, 0 }, { 0, 0 } };
      double nevt[2][2] = { { 0, 0 }, { 0, 0 } };
      //std::cout<<samples[iMethod][iSample]<<":"<<std::endl;
      for (int i=0; i<2; ++i) {
        for (int bin=1; bin<=h_side->GetNbinsX(); ++bin) {
          if (h_signal->GetXaxis()->GetBinLowEdge(bin)>=Rranges_ABCD[iMethod][i*2] && 
              h_signal->GetXaxis()->GetBinUpEdge(bin)<=Rranges_ABCD[iMethod][i*2+1]) {
	    //std::cout<<bin<<"="<<h_side->GetBinCenter(bin);
	    //if (i==0) std::cout<<" in, ";
	    //else std::cout<<" out, ";
            double c0 = h_side->GetBinContent(bin), c1 = h_signal->GetBinContent(bin);
            double e0 = h_side->GetBinError(bin),   e1 = h_signal->GetBinError(bin);
            //std::cout<<h_signal->GetBinError(bin)<<" "<<sqrt(c1*weight[iSample])<<std::endl;
            if (baderror&&iMethod==1) {
              e0 = sqrt(c0*weight[iSample]);
              e1 = sqrt(c1*weight[iSample]);
            }
            nevt[0][i] += (int)(c0*c0/(e0*e0) + 0.5);
            nevt[1][i] += (int)(c1*c1/(e1*e1) + 0.5);
            integral[0][i] += c0;
            integral[1][i] += c1;
            //if (iMethod==1) { // weight bin by projected ratio (correction)
            //  double bincent = h_signal->GetXaxis()->GetBinLowEdge(bin);
            //  integral[0][1] *= fit_ratio->Eval(bincent);
            //}
            integral_error[0][i] += e0*e0;
            integral_error[1][i] += e1*e1;
            //if (iSample==0&&e1>0) std::cout<<bin<<" "<<c1<<" +- "<<e1*e1<<" nevt = "<<((int)(c1*c1/(e1*e1) + 0.5))<<std::endl;
          }
        }
        //if (iSample==1&&i==1) std::cout<<integral[1][i]<<" +- "<<integral_error[1][i]<<std::endl;
        integral_error[0][i] = sqrt(integral_error[0][i]);
        integral_error[1][i] = sqrt(integral_error[1][i]);
      }
      //std::cout<<nevt[1][1]<<std::endl;
      
      // predict yields using 2 methods (ABCD and constrained R-shape fit method combined)
      // ABCD method
      double a = integral[0][0], b = integral[0][1], c = integral[1][0], d = integral[1][1];
      double a_err = integral_error[0][0], b_err = integral_error[0][1], c_err = integral_error[1][0], d_err = integral_error[1][1];
      // Calculate error
      // z = x / y -> z_err = sqrt( (x*x*y_err*y_err + y*y*x_err*x_err)/(y*y*y*y) )
      // z = x * y -> z_err = sqrt ( x*x*y_err*y_err + y*y*x_err*x_err )
      double c_per_a_err = sqrt((c*c*a_err*a_err + a*a*c_err*c_err)/(a*a*a*a));
      double d_abcd = b * (c/a), d_abcd_err = sqrt(b*b*c_per_a_err*c_per_a_err + (c/a)*(c/a)*b_err*b_err);
      double d_nevt = nevt[1][1];
      double d_ratio = d_abcd / d;
      double d_ratio_err = sqrt((d_err/d)*(d_err/d) + (d_abcd_err/d_abcd)*(d_abcd_err/d_abcd))*d_ratio;
      double d_pull = (d_abcd-d)/sqrt(d_abcd_err*d_abcd_err + d_err*d_err);
      // Scaled plot
      h_pred->Scale(c/a);
      h_pred->SetLineColor(1);
      h_pred->SetLineStyle(2);
      h_pred->Draw("SAMEHIST");
      leg->AddEntry(h_pred, "Prediction (ABCD)", "l");
      
      double fit_integral[2][2], fit_integral_error[2][2], d_fit_comb = 0, d_fit_comb_err = 0;
      if (iMethod==1) {
	// Fit in the full range of NTop Sideband
	// Do fitting and calculate integrals
	TF1 *fit_side = new TF1("NTopSide_fit","exp([0]+[1]*x)", iMethod==2 ? 0.2 : sideband_fit_low_range[iSample], Rranges_ABCD[iMethod][3]);
        fit_side->SetLineColor(h_side->GetLineColor());
        h_side->Fit("NTopSide_fit","QRE");
        //fit_side->Draw("SAME");
        double Rranges_ACfit[3] = { sideband_fit_low_range[iSample], Rranges_ABCD[iMethod][2], Rranges_ABCD[iMethod][3] };
        for (int i=0; i<2; ++i) {
          fit_integral[0][i] = fit_side->Integral(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1);
          fit_integral_error[0][i] = fit_side->IntegralError(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1);
        }
        double par0 = fit_side->GetParameter(0), par0_error = fit_side->GetParError(0);
        double par1 = fit_side->GetParameter(1), par1_error = fit_side->GetParError(1);
        double par1min, par1max; fit_side->GetParLimits(1, par1min, par1max);
	
        // Fit in the Signal region
        // Fitting in sideband, get B area under curve and scale by C/A
        TF1 *fit_signal = new TF1("NTopSignal_RSide_fit","exp([0]+[1]*x)", Rranges_ACfit[0], Rranges_ABCD[iMethod][3]);
        fit_signal->SetLineColor(h_signal->GetLineColor());
        //fit_signal->SetParameter(1, par1); 
        //fit_signal->SetParLimits(1, par1min, par1max);
        h_signal->Fit("NTopSignal_RSide_fit","QREB");
        //fit_signal->Draw("SAME");
        for (int i=0; i<2; ++i) {
          fit_integral[1][i] = fit_signal->Integral(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1);
          fit_integral_error[1][i] = fit_signal->IntegralError(Rranges_ACfit[i], Rranges_ACfit[i+1])/h_signal->GetXaxis()->GetBinWidth(1);
        }
        d_fit_comb = fit_integral[0][1] * (c/a);
        d_fit_comb_err = sqrt(fit_integral[0][1]*fit_integral[0][1]*c_per_a_err*c_per_a_err + (c/a)*(c/a)*fit_integral_error[0][1]*fit_integral_error[0][1]);
        TF1 *fit_pred = new TF1("Predicted_fit","exp([0]+[1]*x)", Rranges_ACfit[0], Rranges_ACfit[2]);
        fit_pred->SetLineColor(1);
        fit_pred->SetLineStyle(2);
        fit_pred->FixParameter(0, par0+std::log(c/a)); 
        fit_pred->FixParameter(1, par1); 
        h_signal->Fit("Predicted_fit","QREB+");
        //fit_pred->Draw("SAME");
      }
      // Save plot
      if (iMethod==3) samples[iMethod][iSample] = "T1tttt";
      std::string name = samples[iMethod][iSample];
      if (iMethod==2) name = "AllBkg";
      if (save)	can->SaveAs((out+"BkgEst/ABCD_closure_"+name+"."+ext).c_str());
      
      // Check compatibility of prediction to observed distribution
      double ks_test = h_pred->KolmogorovTest(h_signal);
      
      if (iMethod==1) {
	sum_a += a; sum_b += b; sum_c += c; sum_d += d;
	sum_a_err += a_err*a_err; sum_b_err += b_err*b_err; sum_c_err += c_err*c_err; sum_d_err += d_err*d_err;
	sum_d_abcd += d_abcd; sum_d_abcd_err += d_abcd_err*d_abcd_err;
	sum_b_fit += fit_integral[0][1]; sum_b_fit_err += fit_integral_error[0][1]*fit_integral_error[0][1];
	sum_d_fit += fit_integral[1][1]; sum_d_fit_err += fit_integral_error[1][1]*fit_integral_error[1][1];
	sum_d_fit_comb += d_fit_comb; sum_d_fit_comb_err += d_fit_comb_err*d_fit_comb_err;
	sum_d_nevt += d_nevt;
	//printf("  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |\n", d_fit_comb, d_fit_comb_err, d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err);
      }
      if (latex) {
	printf("%s &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &", samples[iMethod][iSample].c_str(), a, a_err, b, b_err, c, c_err);
	printf("  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  %.2f &  %.2f \\\\\n", d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err, d_pull, ks_test);
      } else {
	printf("| %s |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |", samples[iMethod][iSample].c_str(), a, a_err, b, b_err, c, c_err);
	printf("  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f |  %.2f |\n", d_abcd, d_abcd_err, d, d_err, d_ratio, d_ratio_err, d_pull, ks_test);
      }
      // Combining best methods
      if ((iMethod==0&&iSample==0)||(iMethod==1&&iSample!=0)) {
	comb_d_abcd += d_abcd; comb_d += d; comb_d_abcd_err += d_abcd_err*d_abcd_err; comb_d_err += d_err*d_err;
      }
    }
    if (iMethod==1) {
      sum_a_err = sqrt(sum_a_err); sum_b_err = sqrt(sum_b_err); sum_c_err = sqrt(sum_c_err); sum_d_err = sqrt(sum_d_err);
      sum_b_fit_err = sqrt(sum_b_fit_err); sum_d_fit_err = sqrt(sum_d_fit_err); sum_d_fit_comb_err = sqrt(sum_d_fit_comb_err);
      double sum_d_ratio = sum_d_abcd / sum_d;
      double sum_d_ratio_err = sqrt((sum_d_err/sum_d)*(sum_d_err/sum_d) + (sum_d_abcd_err/sum_d_abcd)*(sum_d_abcd_err/sum_d_abcd))*sum_d_ratio;
      double sum_d_pull = (sum_d_abcd-sum_d)/sqrt(sum_d_abcd_err*sum_d_abcd_err + sum_d_err*sum_d_err);
      if (latex) {
	printf("\\hline\n");
	printf("Sum Bkg. &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &", sum_a, sum_a_err, sum_b, sum_b_err, sum_c, sum_c_err);
	printf("  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  %.2f & \\\\\n", sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err, sum_d_pull);
      } else {
	//printf("| Sum Bkg.|  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |", sum_a, sum_a_err, sum_b_fit, sum_b_fit_err, sum_b, sum_b_err, sum_c, sum_c_err);
	printf("| Sum Bkg.|  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |", sum_a, sum_a_err, sum_b, sum_b_err, sum_c, sum_c_err);
	//printf("  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |\n", sum_d_fit_comb, sum_d_fit_comb_err, sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err);
	printf("  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f |  - |\n", sum_d_abcd, sum_d_abcd_err, sum_d, sum_d_err, sum_d_ratio, sum_d_ratio_err, sum_d_pull);
      }
    } else if (iMethod==2&&samples[0].size()) {
      double comb_d_ratio = comb_d_abcd / comb_d;
      double comb_d_ratio_err = sqrt((comb_d_err/comb_d)*(comb_d_err/comb_d) + (comb_d_abcd_err/comb_d_abcd)*(comb_d_abcd_err/comb_d_abcd))*comb_d_ratio;
      double comb_d_pull = (comb_d_abcd-comb_d)/sqrt(comb_d_abcd_err*comb_d_abcd_err + comb_d_err*comb_d_err);
      if (latex) {
	printf("\\hline\n");
	printf("\\hline\n");
	printf("Combined Bkg. & & & &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  $%.2f \\pm %.2f$ &  %.2f & \\\\\n", comb_d_abcd, comb_d_abcd_err, comb_d, comb_d_err, comb_d_ratio, comb_d_ratio_err, comb_d_pull);
	printf("\\hline\n");
      } else {
	printf("| Combined Bkg.| | | |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f +- %.2f |  %.2f | - |\n", comb_d_abcd, comb_d_abcd_err, comb_d, comb_d_err, comb_d_ratio, comb_d_ratio_err, comb_d_pull);
      }
    }
  }
  if (latex) {
    printf("\\hline\n");
    printf("\\end{tabular}\n");
    printf("\\end{center}\n");
    printf("\\end{table*}\n");
  }

  if (save) gApplication->Terminate();
}